Documentation ¶
Index ¶
- Constants
- func GenCryptoPasswordHash(password string, makeKeyHash bool, keyHashOpts string) (key []byte, keyHash []byte, keyHashCombo string, err error)
- func GenLoginPasswordHash(unsaltedPassword string) (salt string, saltedhash []byte, err error)
- func VerifyCryptoPassword(password string, keyHashCombo string) ([]byte, error)
- func VerifyLoginPassword(unsaltedPassowrd string, salt string, saltedHash []byte) bool
- type FileChunk
- type FileInfo
- type FileStats
- type FileVersionInfo
- type Storage
- func (s *Storage) AddFileChunk(userID int, fileID int, versionID int, chunkNumber int, chunkHash string, ...) (*FileChunk, error)
- func (s *Storage) AddFileInfo(userID int, filename string, isDir bool, permissions uint32, lastMod int64, ...) (*FileInfo, error)
- func (s *Storage) AddUser(username string, salt string, saltedHash []byte, quota int) (*User, error)
- func (s *Storage) Close()
- func (s *Storage) CreateTables() error
- func (s *Storage) GetAllUserFileInfos(userID int) ([]FileInfo, error)
- func (s *Storage) GetDBVersion() (int, error)
- func (s *Storage) GetFileChunk(fileID int, chunkNumber int, versionID int) (fc *FileChunk, e error)
- func (s *Storage) GetFileChunkInfos(userID int, fileID int, versionID int) ([]FileChunk, error)
- func (s *Storage) GetFileInfo(userID int, fileID int) (*FileInfo, error)
- func (s *Storage) GetFileInfoByName(userID int, filename string) (*FileInfo, error)
- func (s *Storage) GetFileVersions(fileID int) ([]FileVersionInfo, error)
- func (s *Storage) GetMissingChunkNumbersForFile(userID int, fileID int) ([]int, error)
- func (s *Storage) GetUser(username string) (*User, error)
- func (s *Storage) GetUserStats(userID int) (*UserStats, error)
- func (s *Storage) IsUsernameFree(username string) (bool, error)
- func (s *Storage) RemoveFile(userID, fileID int) error
- func (s *Storage) RemoveFileChunk(userID int, fileID int, versionID int, chunkNumber int) (bool, error)
- func (s *Storage) RemoveFileInfo(fileID int) error
- func (s *Storage) RemoveFileVersions(userID, fileID, minVersion, maxVersion int) error
- func (s *Storage) RemoveUser(username string) error
- func (s *Storage) SetUserQuota(userID int, quota int) error
- func (s *Storage) SetUserStats(userID int, quota int, allocated int, revision int) error
- func (s *Storage) TagNewFileVersion(userID int, fileID int, permissions uint32, lastMod int64, chunkCount int, ...) (*FileInfo, error)
- func (s *Storage) UpdateUser(userID int, name string, salt string, saltedHash []byte, cryptoHash []byte, ...) error
- func (s *Storage) UpdateUserCryptoHash(userID int, cryptoHash []byte) error
- func (s *Storage) UpdateUserStats(userID int, allocDelta int) error
- type User
- type UserStats
Constants ¶
const ( // CurrentDBVersion is set to the current database version and is used // by filefreezer to detect when the database tables need to get updated. CurrentDBVersion = 1 )
Variables ¶
This section is empty.
Functions ¶
func GenCryptoPasswordHash ¶
func GenCryptoPasswordHash(password string, makeKeyHash bool, keyHashOpts string) (key []byte, keyHash []byte, keyHashCombo string, err error)
GenCryptoPasswordHash takes the user password then generates a crytpo hash. If makeKeyHash is false, only the key parameter is generated. If keyHashOpts is not an empty string, it attempts to split the string by '$' dividers for scrypt parameters. NOTE: it's intended that keyHashOpts will be the keyHashCombo return value of a previous call.
func GenLoginPasswordHash ¶
GenLoginPasswordHash takes the user password, generates a new random salt, then generates a hash from the salted password combination.
func VerifyCryptoPassword ¶
VerifyCryptoPassword takes a plain text password and compares it against a hash of the crypto key to verify that the password is correct and the crypto key is the correct one. On success and successful match a non-nil []byte slice is returned. If the keys do not match nil is returned. Otherwise an non-nil error is returned.
func VerifyLoginPassword ¶
VerifyLoginPassword takes the user-supplied unsalted password and the stored salt and hash and verifies that the supplied unsalted password is the correct match. Returns true on match and false on fail.
Types ¶
type FileInfo ¶
type FileInfo struct { UserID int FileID int FileName string IsDir bool CurrentVersion FileVersionInfo }
FileInfo contains the information stored about a given file for a particular user.
type FileStats ¶
type FileStats struct { ChunkCount int LastMod int64 Permissions uint32 HashString string IsDir bool }
FileStats is a structure used to return information about a given file from the file system.
type FileVersionInfo ¶
type FileVersionInfo struct { VersionID int VersionNumber int Permissions uint32 LastMod int64 ChunkCount int FileHash string }
FileVersionInfo contains the version-specific information for a given file.
type Storage ¶
type Storage struct { // ChunkSize is the number of bytes the chunk can maximally be ChunkSize int64 // contains filtered or unexported fields }
Storage is the backend data model for the file storage logic.
func NewStorage ¶
NewStorage creates a new Storage object using the sqlite3 driver at the path given.
func (*Storage) AddFileChunk ¶
func (s *Storage) AddFileChunk(userID int, fileID int, versionID int, chunkNumber int, chunkHash string, chunk []byte) (*FileChunk, error)
AddFileChunk adds a binary chunk to storage for a given file at a position in the file determined by the chunkNumber passed in and identified by the chunkHash. The userID is used to update the allocation count in the same transaction as well as verify ownership.
func (*Storage) AddFileInfo ¶
func (s *Storage) AddFileInfo(userID int, filename string, isDir bool, permissions uint32, lastMod int64, chunkCount int, fileHash string) (*FileInfo, error)
AddFileInfo registers a new file for a given user which is identified by the filename string. lastmod (time in seconds since 1/1/1970) and the filehash string are provided as well. The chunkCount parameter should be the number of chunks required for the size of the file. If the file could not be added an error is returned, otherwise nil on success.
func (*Storage) AddUser ¶
func (s *Storage) AddUser(username string, salt string, saltedHash []byte, quota int) (*User, error)
AddUser should create the user in the USERS table. The username should be unique. saltedHash should be the combined password & salt hash and salt should be the user specific generated salt. This function returns a true bool value if a user was created and false if the user was not created (e.g. username was already taken).
func (*Storage) Close ¶
func (s *Storage) Close()
Close releases the backend connections to the database.
func (*Storage) CreateTables ¶
CreateTables will create the tables needed in the database if they don't already exist. If the tables already exist an error will be returned.
func (*Storage) GetAllUserFileInfos ¶
GetAllUserFileInfos returns a slice of UserFileInfo objects that describe all known files in storage for a given user ID. If this query was unsuccessful and error is returned.
func (*Storage) GetDBVersion ¶
GetDBVersion will return the DB Version number for the opened database.
func (*Storage) GetFileChunk ¶
GetFileChunk retrieves a file chunk from storage and returns it. An error value is returned on failure.
func (*Storage) GetFileChunkInfos ¶
GetFileChunkInfos returns a slice of FileChunks containing all of the chunk information except for the chunk bytes themselves.
func (*Storage) GetFileInfo ¶
GetFileInfo returns a UserFileInfo object that describes the file identified by the fileID parameter. If this query was unsuccessful an error is returned.
func (*Storage) GetFileInfoByName ¶
GetFileInfoByName returns a UserFileInfo object that describes the file identified by the userID and filename parameters. If this query was unsuccessful an error is returned.
func (*Storage) GetFileVersions ¶
func (s *Storage) GetFileVersions(fileID int) ([]FileVersionInfo, error)
GetFileVersions will return a slice of FileVersionInfo that encompases all of the versions registered for a given file ID.
func (*Storage) GetMissingChunkNumbersForFile ¶
GetMissingChunkNumbersForFile will return a slice of chunk numbers that have not been added for a given file.
func (*Storage) GetUser ¶
GetUser queries the Users table for a given username and returns the associated data. If the query fails and error will be returned.
func (*Storage) GetUserStats ¶
GetUserStats returns the user information for a user by user id.
func (*Storage) IsUsernameFree ¶
IsUsernameFree will return true if there is not already a username with the same text in the Users table.
func (*Storage) RemoveFile ¶
RemoveFile removes a file listing and all of the associated chunks in storage. Returns an error on failure
func (*Storage) RemoveFileChunk ¶
func (s *Storage) RemoveFileChunk(userID int, fileID int, versionID int, chunkNumber int) (bool, error)
RemoveFileChunk removes a chunk from storage identifed by the fileID and chunkNumber. If the chunkNumber specified is out of range of the file's max chunk count, this will simply have no effect. An bool indicating if the chunk was successfully removed is returned as well as an error on failure. userID is required so that the allocation count can updated in the same transaction as well as to verify ownership of the chunk.
func (*Storage) RemoveFileInfo ¶
RemoveFileInfo removes a file listing in storage, returning an error on failure.
func (*Storage) RemoveFileVersions ¶
RemoveFileVersions will remove any file versions of the file specified by fileID that are between the minVersion and maxVersion (inclusive). A non-nil error value is returned on failure.
NOTE: supplying a minVersion and maxVersion that does not include any valid file versions will end up returning an error.
func (*Storage) RemoveUser ¶
RemoveUser removes user and all files and file chunks associated with the user.
func (*Storage) SetUserQuota ¶
SetUserQuota sets the user quota for a user by user id.
func (*Storage) SetUserStats ¶
SetUserStats sets the user information for a user by user id and is used to do the first insertion of the user into the stats table.
func (*Storage) TagNewFileVersion ¶
func (s *Storage) TagNewFileVersion(userID int, fileID int, permissions uint32, lastMod int64, chunkCount int, fileHash string) (*FileInfo, error)
TagNewFileVersion creates a new version of a given file and returns the new version ID as well as the incremented file-local version number.
func (*Storage) UpdateUser ¶
func (s *Storage) UpdateUser(userID int, name string, salt string, saltedHash []byte, cryptoHash []byte, quota int) error
UpdateUser changes the salt, saltedHash, cryptoHash and quota for a given userID. This will fail if the userID doesn't exist.
func (*Storage) UpdateUserCryptoHash ¶
UpdateUserCryptoHash changes the cryptoHash for a given userID. This will fail if the userID doesn't exist.