go_sshkeys/cipher/types.go

51 lines
2.0 KiB
Go

package cipher
import (
`bytes`
)
type Cipher interface {
// Setup initializes the Cipher with a given key.
Setup(key []byte) (err error)
// Name returns the string form of the cipher name.
Name() (name string)
// NameBytes returns the Name result but in bytes, with a leading uint32 bytecount packed in.
NameBytes() (name []byte)
// BlockSize returns the blocksize of the cipher.Cipher. This is used for externally padding data for Cipher.Encrypt and Cipher.AllocateEncrypt.
BlockSize() (size int)
// KdfKeySize returns the desired/needed key size for use with kdf.KDF.
KdfKeySize() (size int)
/*
Encrypt takes plain data, either a:
- string
- raw byte slice ([]byte or []uint8)
- single byte (byte or uint8)
- *bytes.Buffer
and returns an encrypted *bytes.Buffer of data.
*/
Encrypt(data interface{}) (encrypted *bytes.Reader, err error)
// AllocateEncrypt is exactly like cipher.Cipher.Encrypt except that it includes a (NON-encrypted) uint32 prefix of byte allocation.
AllocateEncrypt(data interface{}) (encrypted *bytes.Reader, err error)
/*
Pad returns padded bytes in a *bytes.Buffer according to the cipher's padding specification.
data can be one of either:
- string
- raw byte slice ([]byte or []uint8)
- single byte (byte or uint8)
- *bytes.Buffer
This is a prerequisite in some ciphers, and must be performed BEFORE encrypting.
*/
Pad(data interface{}) (paddedBuf *bytes.Reader, err error)
/*
Decrypt takes encrypted data, either a:
- raw byte slice ([]byte or []uint8)
- *bytes.Buffer
and returns a plain/decrypted *bytes.Buffer of data.
*/
Decrypt(data interface{}) (decrypted *bytes.Reader, err error)
// AllocatedDecrypt is exactly like cipher.Cipher.Decrypt except that it assumes that data includes a (NON-encrypted) uint32 prefix of byte allocation.
AllocatedDecrypt(data interface{}) (decrypted *bytes.Reader, err error)
// IsPlain returns true if this is a "null" cipher; i.e. no encryption is actually performed.
IsPlain() (plain bool)
}