Documentation ¶
Index ¶
- Constants
- func CreateTransferMAC(fileData []byte, key TransferKey) []byte
- func DecryptPart(transferKey TransferKey, ciphertext, mac []byte, fpNum uint16, ...) (filePartBytes []byte, err error)
- func EncryptPart(transferKey TransferKey, partBytes []byte, fpNum uint16, fp format.Fingerprint) (ciphertext, mac []byte)
- func GenerateFingerprint(transferKey TransferKey, fpNum uint16) format.Fingerprint
- func GenerateFingerprints(startKey TransferKey, numFingerprints uint16) []format.Fingerprint
- func VerifyTransferMAC(fileData []byte, key TransferKey, mac []byte) bool
- type ID
- type TransferID
- type TransferKey
Constants ¶
const IdLen = 32
IdLen is the length of a File ID.
const TransferIdLength = 32
TransferIdLength is the length, in bytes, of the TransferKey.
const (
TransferKeyLength = 32
)
Key length constants, in bytes.
Variables ¶
This section is empty.
Functions ¶
func CreateTransferMAC ¶
func CreateTransferMAC(fileData []byte, key TransferKey) []byte
CreateTransferMAC creates a MAC for the entire file. This is for consistency upon reconstruction of the file parts.
func DecryptPart ¶
func DecryptPart(transferKey TransferKey, ciphertext, mac []byte, fpNum uint16, fp format.Fingerprint) (filePartBytes []byte, err error)
DecryptPart decrypts an individual file part. The part key and nonce are used to decrypt the ciphertext.
func EncryptPart ¶
func EncryptPart(transferKey TransferKey, partBytes []byte, fpNum uint16, fp format.Fingerprint) (ciphertext, mac []byte)
EncryptPart encrypts an individual file part using a nonce and part key. The part key is generated from the transfer key and the fingerprint number. A random nonce is generated as padding for the ciphertext and used as part of the encryption.
func GenerateFingerprint ¶
func GenerateFingerprint( transferKey TransferKey, fpNum uint16) format.Fingerprint
GenerateFingerprint generates an individual fingerprint for a file part given the fingerprint number.
func GenerateFingerprints ¶
func GenerateFingerprints( startKey TransferKey, numFingerprints uint16) []format.Fingerprint
GenerateFingerprints generates the key fingerprints for all file parts.
func VerifyTransferMAC ¶
func VerifyTransferMAC(fileData []byte, key TransferKey, mac []byte) bool
VerifyTransferMAC verifies that the transfer MAC matches the received file data. This is for consistency upon reconstruction
Types ¶
type ID ¶
ID identifies each unique file. It is a perceptual hash of a file so that all files that are the same and extremely similar share the same ID.
func UnmarshalID ¶
UnmarshalID converts the byte slice to a file ID.
func (ID) MarshalJSON ¶
MarshalJSON adheres to the json.Marshaler interface.
func (ID) String ¶
String returns the file ID as a base 64 encoded string. This function adheres to the fmt.Stringer interface.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON adheres to the json.Unmarshaler interface.
type TransferID ¶
type TransferID [TransferIdLength]byte
TransferID is a 256-bit randomly generated ID that is used to track the transfer progress of a file transfer.
func NewTransferID ¶
func NewTransferID(rng csprng.Source) (TransferID, error)
NewTransferID generates a new TransferID. Returns an error if an error occurs when generating random bytes or if the number of generated bytes is insufficient.
func UnmarshalTransferID ¶
func UnmarshalTransferID(b []byte) TransferID
UnmarshalTransferID converts the byte slice to a TransferID.
func (*TransferID) Bytes ¶
func (tid *TransferID) Bytes() []byte
Bytes returns the TransferID as a byte slice.
func (*TransferID) MarshalJSON ¶
func (tid *TransferID) MarshalJSON() ([]byte, error)
MarshalJSON is part of the json.Marshaler interface and allows TransferID objects to be marshaled into JSON.
func (*TransferID) String ¶
func (tid *TransferID) String() string
String returns the TransferID as a base 64 encoded string. This functions satisfies the fmt.Stringer interface.
func (*TransferID) UnmarshalJSON ¶
func (tid *TransferID) UnmarshalJSON(b []byte) error
UnmarshalJSON is part of the json.Unmarshaler interface and allows JSON to be unmarshalled into TransferID objects.
type TransferKey ¶
type TransferKey [TransferKeyLength]byte
TransferKey is the 256-bit key used to generate the MAC for a file transfer.
func NewTransferKey ¶
func NewTransferKey(rng csprng.Source) (TransferKey, error)
NewTransferKey creates a new TransferKey to be used for encryption when transferring a file to another user. Returns an error if an error occurs when generating random bytes or if the number of generated bytes is insufficient.
func UnmarshalTransferKey ¶
func UnmarshalTransferKey(b []byte) TransferKey
UnmarshalTransferKey converts the byte slice to a TransferKey.
func (*TransferKey) Bytes ¶
func (tr *TransferKey) Bytes() []byte
Bytes returns the TransferKey as a byte slice.
func (*TransferKey) MarshalJSON ¶
func (tr *TransferKey) MarshalJSON() ([]byte, error)
MarshalJSON is part of the json.Marshaler interface and allows TransferKey objects to be marshaled into JSON.
func (*TransferKey) String ¶
func (tr *TransferKey) String() string
String returns the TransferKey as a base 64 encoded string. This functions satisfies the fmt.Stringer interface.
func (*TransferKey) UnmarshalJSON ¶
func (tr *TransferKey) UnmarshalJSON(b []byte) error
UnmarshalJSON is part of the json.Unmarshaler interface and allows JSON to be unmarshalled into TransferKey objects.