Documentation ¶
Index ¶
- Constants
- Variables
- func Decrypt(msg, nonce, pubkey, privkey common.RawBytes, algo string) (common.RawBytes, error)
- func Encrypt(msg, nonce, pubkey, privkey common.RawBytes, algo string) (common.RawBytes, error)
- func GenKeyPair(algo string) (common.RawBytes, common.RawBytes, error)
- func GetPubKey(privKey []byte, algo string) ([]byte, error)
- func HFMacFactory(key []byte) (func() hash.Hash, error)
- func InitMac(key []byte) (hash.Hash, error)
- func JWSignatureInput(protected []byte, payload []byte) common.RawBytes
- func Nonce(l int) (common.RawBytes, error)
- func RandInt64() int64
- func RandUint64() uint64
- func Sign(sigInput, signKey common.RawBytes, signAlgo string) (common.RawBytes, error)
- func Verify(sigInput, sig, verifyKey common.RawBytes, signAlgo string) error
- type KeyMeta
- type KeyVersion
- type Validity
- type Version
Constants ¶
const ( Ed25519 = "ed25519" Curve25519xSalsa20Poly1305 = "curve25519xsalsa20poly1305" )
Available asymmetric crypto algorithms. The values must be lower case.
const ( NaClBoxNonceSize = 24 NaClBoxKeySize = 32 )
Constants for nacl/box implementation of Curve25519xSalsa20Poly1305
const ( ErrInvalidPubKeySize common.ErrMsg = "Invalid public key size" ErrInvalidPrivKeySize common.ErrMsg = "Invalid private key size" ErrInvalidSignatureSize common.ErrMsg = "Invalid signature size" ErrInvalidSignatureFormat common.ErrMsg = "Invalid signature format: " + "sig[63]&224 should equal 0" ErrVerification common.ErrMsg = "Signature verification failed" ErrUnableToGenerateKeyPair common.ErrMsg = "Unable to generate key pair" ErrUnableToDecrypt common.ErrMsg = "Unable to decrypt message" ErrUnsupportedAlgo common.ErrMsg = "Unsupported algorithm" ErrUnsupportedSignAlgo common.ErrMsg = "Unsupported signing algorithm" ErrUnsupportedEncAlgo common.ErrMsg = "Unsupported encryption algorithm" )
const ( ErrCipherFailure common.ErrMsg = "Unable to initialize AES cipher" ErrMacFailure common.ErrMsg = "Unable to initialize Mac" )
const ( ErrInvalidNonceSize common.ErrMsg = "Invalid nonce size" ErrUnableToGenerateNonce common.ErrMsg = "Unable to generate nonce" )
Variables ¶
var ( // ErrKeyVersionNotSet indicates KeyVersion is not set. ErrKeyVersionNotSet = errors.New("key version not set") // ErrAlgorithmNotSet indicates the key algorithm is not set. ErrAlgorithmNotSet = errors.New("algorithm not set") // ErrKeyNotSet indicates the key is not set. ErrKeyNotSet = errors.New("key not set") )
var ( // ErrNotAfterNotSet indicates not_after is not set. ErrNotAfterNotSet = errors.New("not_after not set") // ErrNotBeforeNotSet indicates not_before is not set. ErrNotBeforeNotSet = errors.New("not_before not set") // ErrInvalidValidityPeriod indicates an invalid validity period. ErrInvalidValidityPeriod = errors.New("not_after before not_before") )
var Base64 = base64.RawURLEncoding
Base64 is the base64 encoding used when packing and unpacking encoded data. In accordance with rfc7515 (see https://tools.ietf.org/html/rfc7515#section-2), this is the URL safe encoding with padding omitted.
var ErrInvalidVersion = errors.New("version must not be zero")
ErrInvalidVersion indicates an invalid trust file version.
Functions ¶
func Encrypt ¶
Encrypt takes a message, a nonce and a public/private keypair and returns the encrypted and authenticated message. Note: Nonce must be different for each message that is encrypted with the same key.
func GenKeyPair ¶
GenKeyPair generates a public/private key pair.
func JWSignatureInput ¶ added in v0.4.0
JWSignatureInput computes the signature input according to rfc7517 (see: https://tools.ietf.org/html/rfc7515#section-5.1)
func RandInt64 ¶
func RandInt64() int64
RandInt64 returns a random int64 value. The returned value can be negative.
func RandUint64 ¶
func RandUint64() uint64
Types ¶
type KeyMeta ¶ added in v0.4.0
type KeyMeta struct { // KeyVersion identifies the key. It must change if the key changes, and // stay the same if the key does not change. KeyVersion KeyVersion `json:"key_version"` // Algorithm indicates the algorithm associated with the key. Algorithm string `json:"algorithm"` // Key is the raw public key. Key common.RawBytes `json:"key"` }
KeyMeta holds the raw key with metadata.
func (*KeyMeta) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON checks that all fields are set.
type Validity ¶ added in v0.4.0
type Validity struct { NotBefore util.UnixTime `json:"not_before"` NotAfter util.UnixTime `json:"not_after"` }
Validity indicates a validity period.
func (Validity) Contains ¶ added in v0.4.0
Contains indicates whether the provided time is inside the validity period.
func (Validity) Covers ¶ added in v0.4.0
Covers indicates whether the other validity is covered by this validity.
func (*Validity) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON checks that both NotBefore and NotAfter are set.
type Version ¶ added in v0.4.0
type Version uint64
Version identifies the version of a trust file. It cannot be marshalled/unmarshalled to/from LatestVer.
const LatestVer Version = 0
LatestVer is the wildcard version indicating the highest available version when requesting certificate chains and TRCs.
func (Version) MarshalJSON ¶ added in v0.4.0
MarshalJSON checks that the value is not LatestVer.
func (*Version) UnmarshalJSON ¶ added in v0.4.0
UnmarshalJSON checks that the value is not LatestVer.