Documentation ¶
Overview ¶
Package crypto contains functionality for dealing with X509 certificates and cryptography.
Index ¶
- Constants
- func DecodePEMBlockFromFile(file string, ctx context.Context) (*pem.Block, error)
- func DecryptPEMBlock(b *pem.Block, password []byte, ctx context.Context) ([]byte, error)
- func DecryptString(ciphertext, key string, ctx context.Context) (string, error)
- func EncryptPEMBlock(rand io.Reader, blockType string, data, password []byte, alg PEMCipher, ...) (*pem.Block, error)
- func EncryptString(plaintext, key string, ctx context.Context) (string, error)
- func GeneratePassword(passwordLength, minSpecialChar, minNum, minUpperCase int) string
- func IsEncryptedPEMBlock(b *pem.Block) bool
- func NewSelfSignedCertificateKeyPair(template *x509.Certificate, keyBits int, ctx context.Context) ([]byte, []byte, error)
- func ParsePEMCertificateBytes(contents []byte, ctx context.Context) ([]*x509.Certificate, error)
- func ParsePEMCertificateFile(file string, ctx context.Context) ([]*x509.Certificate, error)
- func ParsePEMPrivateKeyBytes(contents []byte, password []byte, ctx context.Context) (*rsa.PrivateKey, error)
- func ParsePEMPrivateKeyFile(file string, password []byte, ctx context.Context) (*rsa.PrivateKey, error)
- func ParsePublicKeyFromCertificate(cert *x509.Certificate, ctx context.Context) (*rsa.PublicKey, error)
- func Sign(contents []byte, privateKey *rsa.PrivateKey, ctx context.Context) ([]byte, error)
- func ValidateCertificate(cert *x509.Certificate, roots *CertificatePool, intermediates *CertificatePool, ...) error
- func Verify(contents, signature []byte, publicKey *rsa.PublicKey, ctx context.Context) error
- type CertificatePool
- type ErrArmorPGPKeyFailure
- type ErrDecodeFailure
- type ErrDecryptFailure
- type ErrEncodeFailure
- type ErrEncryptFailure
- type ErrExtractPublicKeyFailure
- type ErrGenerateCertificateFailure
- type ErrGenerateCipherFailure
- type ErrGenerateGCMFailure
- type ErrGenerateIVFailure
- type ErrGenerateNonceFailure
- type ErrGeneratePGPKeyFailure
- type ErrGeneratePrivateKeyFailure
- type ErrGenerateRandomKeyFailure
- type ErrGetPGPKeyFailure
- type ErrInvalidCertificate
- type ErrInvalidSignature
- type ErrInvalidTokenClaims
- type ErrInvalidTokenSignatureAlgorithm
- type ErrLoadCertificateFailure
- type ErrLoadPGPKeyFailure
- type ErrLockPGPKeyFailure
- type ErrParseCertificateFailure
- type ErrParseJWTTokenFailure
- type ErrReadFileFailure
- type ErrSignDataFailure
- type ErrSignJWTTokenFailure
- type ErrUnlockPGPKeyFailure
- type JWTAuthECDSAService
- type JWTAuthHMACService
- type JWTAuthRSAService
- type JWTAuthService
- type PEMCipher
- type PGPKeyPair
Constants ¶
const ( ErrDecodeFailureCode = 1251 ErrGenerateCipherFailureCode = 1252 ErrGenerateGCMFailureCode = 1253 ErrDecryptFailureCode = 1254 ErrGenerateRandomKeyFailureCode = 1255 ErrGenerateNonceFailureCode = 1256 ErrReadFileFailureCode = 1257 ErrEncryptFailureCode = 1258 ErrGenerateIVFailureCode = 1259 ErrParseCertificateFailureCode = 1260 ErrGeneratePGPKeyFailureCode = 1261 ErrLockPGPKeyFailureCode = 1262 ErrArmorPGPKeyFailureCode = 1263 ErrLoadPGPKeyFailureCode = 1264 ErrUnlockPGPKeyFailureCode = 1265 ErrGetPGPKeyFailureCode = 1266 ErrExtractPublicKeyFailureCode = 1267 ErrSignDataFailureCode = 1268 ErrInvalidSignatureCode = 1269 ErrLoadCertificateFailureCode = 1270 ErrInvalidCertificateCode = 1271 ErrGeneratePrivateKeyFailureCode = 1272 ErrGenerateCertificateFailureCode = 1273 ErrEncodeFailureCode = 1274 ErrSignJWTTokenFailureCode = 1275 ErrInvalidJWTTokenSignatureAlgorithmCode = 1276 ErrInvalidJWTTokenClaimsCode = 1277 ErrParseJWTTokenFailureCode = 1278 )
Object error codes (1251-1500)
Variables ¶
This section is empty.
Functions ¶
func DecodePEMBlockFromFile ¶
DecodePEMBlockFromFile loads a file into memory and decodes any PEM data from it.
The following errors are returned by this function: ErrReadFileFailure
func DecryptPEMBlock ¶
DecryptPEMBlock takes a PEM block encrypted according to RFC 1423 and the password used to encrypt it and returns a slice of decrypted DER encoded bytes.
It inspects the DEK-Info header to determine the algorithm used for decryption. If no DEK-Info header is present, an error is returned. If an incorrect password is detected an IncorrectPasswordError is returned. Because of deficiencies in the format, it's not always possible to detect an incorrect password. In these cases no error will be returned but the decrypted DER bytes will be random noise.
The following errors are returned by this function: ErrDecryptFailure
func DecryptString ¶
DecryptString decrypts the given block of ciphertext that was encrypted using the EncryptString() function.
If the string was encrypted using a random key generated by EncryptString(), leave the key empty.
The following errors are returned by this function: ErrDecodeFailure, ErrGenerateCipherFailure, ErrGenerateGCMFailure, ErrDecryptFailure
func EncryptPEMBlock ¶
func EncryptPEMBlock(rand io.Reader, blockType string, data, password []byte, alg PEMCipher, ctx context.Context) ( *pem.Block, error)
EncryptPEMBlock returns a PEM block of the specified type holding the given DER encoded data encrypted with the specified algorithm and password according to RFC 1423.
The following errors are returned by this function: ErrEncryptFailure, ErrGenerateIVFailure
func EncryptString ¶
EncryptString encrypts the given string using the given key.
If the key is empty, a random key is generated and stored with the ciphertext.
The following errors are returned by this function: ErrGenerateRandomKeyFailure, ErrGenerateCipherFailure, ErrGenerateGCMFailure, ErrGenerateNonceFailure
func GeneratePassword ¶
GeneratePassword generates a random password with the given characteristics.
func IsEncryptedPEMBlock ¶
IsEncryptedPEMBlock returns whether the PEM block is password encrypted according to RFC 1423.
func NewSelfSignedCertificateKeyPair ¶
func NewSelfSignedCertificateKeyPair(template *x509.Certificate, keyBits int, ctx context.Context) ( []byte, []byte, error)
NewSelfSignedCertificateKeyPair creates a new self-signed certificate using the given template and returns the public certificate and private key, respectively, on success.
The following errors are returned by this function:
func ParsePEMCertificateBytes ¶
ParsePEMCertificateBytes takes a PEM-formatted byte string and converts it into one or more X509 certificates.
The following errors are returned by this function: ErrDecryptFailure, ErrDecodeFailure, ErrParseCertificateFailure
func ParsePEMCertificateFile ¶
ParsePEMCertificateFile takes a PEM-formatted file and converts it into one or more X509 certificates.
The following errors are returned by this function: ErrReadFileFailure, any error returned by ParsePEMCertificateBytes
func ParsePEMPrivateKeyBytes ¶
func ParsePEMPrivateKeyBytes(contents []byte, password []byte, ctx context.Context) (*rsa.PrivateKey, error)
ParsePEMPrivateKeyBytes takes a PEM-formatted byte string and converts it into an RSA private key.
If the private key is encrypted, be sure to include a password or else this function will return an error. If no password is required, you can safely pass nil for the password.
The following errors are returned by this function: ErrDecryptFailure, ErrDecodeFailure
func ParsePEMPrivateKeyFile ¶
func ParsePEMPrivateKeyFile(file string, password []byte, ctx context.Context) (*rsa.PrivateKey, error)
ParsePEMPrivateKeyFile takes a PEM-formatted file and converts it into an RSA private key.
If the private key is encrypted, be sure to include a password or else this function will return an error. If no password is required, you can safely pass nil for the password.
The following errors are returned by this function: ErrReadFileFailure, any error returned by ParsePEMPrivateKeyBytes
func ParsePublicKeyFromCertificate ¶
func ParsePublicKeyFromCertificate(cert *x509.Certificate, ctx context.Context) (*rsa.PublicKey, error)
ParsePublicKeyFromCertificate parses the RSA public key portion from an X509 certificate.
The following errors are returned by this function: ErrExtractPublicKeyFailure
func Sign ¶
Sign takes the content and generates a signature using a private key certificate.
Use the DecodePEMData() function to convert a PEM-formatted certificate into a PEM block. If the private key is encrypted, use the DecryptPEMBlock() function to decrypt it first.
Use the Verify() function to verify the signature produced for the content.
The following errors are returned by this function: ErrSignDataFailure
func ValidateCertificate ¶
func ValidateCertificate(cert *x509.Certificate, roots *CertificatePool, intermediates *CertificatePool, keyUsages []x509.ExtKeyUsage, cn string, ctx context.Context) error
ValidateCertificate verifies the given certificate is completely trusted.
If the certificate was signed with a key that is not trusted by the default system certificate pool, be sure to specify a root CA certificate pool and, if necessary, an intermediate pool containing the certificates required to verify the chain.
If you wish to match against specific X509 extended key usages such as verifying the signing key has the Code Signing key usage, pass those fields in the keyUsages parameter.
If you wish to verify the common name (CN) field of the public key passed in, specify a non-empty string for the cn parameter. This match is case-sensitive.
The following errors are returned by this function: ErrInvalidCertificate
func Verify ¶
Verify validates that the given contents have not been altered by checking them against the signature and public key provided.
Use the Sign() function to create the signature used by this function to ensure the same hashing algorithm is applied.
The following errors are returned by this function: ErrInvalidSignature
Types ¶
type CertificatePool ¶
CertificatePool stores X509 certificates.
func NewCertificatePool ¶
func NewCertificatePool(emptyPool bool, ctx context.Context) (*CertificatePool, error)
NewCertificatePool creates a new CertificatePool object.
If empty is true, return an empty certificate pool instead of a pool containing a copy of all of the system's trusted root certificates.
The following errors are returned by this function: ErrLoadCertificateFailure
func (*CertificatePool) AddPEMCertificatesFromFile ¶
func (p *CertificatePool) AddPEMCertificatesFromFile(file string, ctx context.Context) error
AddPEMCertificatesFromFile adds one or more PEM-formatted certificates from a file to the certificate pool.
The following errors are returned by this function: ErrLoadCertificateFailure
type ErrArmorPGPKeyFailure ¶ added in v0.1.5
ErrArmorPGPKeyFailure occurs when a PGP key cannot be wrapped in armor.
func (*ErrArmorPGPKeyFailure) Code ¶ added in v0.1.5
func (e *ErrArmorPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrArmorPGPKeyFailure) Error ¶ added in v0.1.5
func (e *ErrArmorPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrArmorPGPKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrArmorPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrDecodeFailure ¶ added in v0.1.5
type ErrDecodeFailure struct {
Err error
}
ErrDecodeFailure occurs when encoded data cannot be decoded.
func (*ErrDecodeFailure) Code ¶ added in v0.1.5
func (e *ErrDecodeFailure) Code() int
Code returns the corresponding error code.
func (*ErrDecodeFailure) Error ¶ added in v0.1.5
func (e *ErrDecodeFailure) Error() string
Error returns the string version of the error.
func (*ErrDecodeFailure) InternalError ¶ added in v0.1.9
func (e *ErrDecodeFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrDecryptFailure ¶ added in v0.1.5
type ErrDecryptFailure struct {
Err error
}
ErrDecryptFailure occurs when data cannot be decrypted.
func (*ErrDecryptFailure) Code ¶ added in v0.1.5
func (e *ErrDecryptFailure) Code() int
Code returns the corresponding error code.
func (*ErrDecryptFailure) Error ¶ added in v0.1.5
func (e *ErrDecryptFailure) Error() string
Error returns the string version of the error.
func (*ErrDecryptFailure) InternalError ¶ added in v0.1.9
func (e *ErrDecryptFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrEncodeFailure ¶ added in v0.1.5
type ErrEncodeFailure struct {
Err error
}
ErrEncodeFailure occurs when data cannot be encoded.
func (*ErrEncodeFailure) Code ¶ added in v0.1.5
func (e *ErrEncodeFailure) Code() int
Code returns the corresponding error code.
func (*ErrEncodeFailure) Error ¶ added in v0.1.5
func (e *ErrEncodeFailure) Error() string
Error returns the string version of the error.
func (*ErrEncodeFailure) InternalError ¶ added in v0.1.9
func (e *ErrEncodeFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrEncryptFailure ¶ added in v0.1.5
type ErrEncryptFailure struct {
Err error
}
ErrEncryptFailure occurs when data fails to be encrypted.
func (*ErrEncryptFailure) Code ¶ added in v0.1.5
func (e *ErrEncryptFailure) Code() int
Code returns the corresponding error code.
func (*ErrEncryptFailure) Error ¶ added in v0.1.5
func (e *ErrEncryptFailure) Error() string
Error returns the string version of the error.
func (*ErrEncryptFailure) InternalError ¶ added in v0.1.9
func (e *ErrEncryptFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrExtractPublicKeyFailure ¶ added in v0.1.5
type ErrExtractPublicKeyFailure struct {
Err error
}
ErrExtractPublicKeyFailure occurs when the public key cannot be extracted from an X509 certificate.
func (*ErrExtractPublicKeyFailure) Code ¶ added in v0.1.5
func (e *ErrExtractPublicKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrExtractPublicKeyFailure) Error ¶ added in v0.1.5
func (e *ErrExtractPublicKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrExtractPublicKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrExtractPublicKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateCertificateFailure ¶ added in v0.1.5
type ErrGenerateCertificateFailure struct {
Err error
}
ErrGenerateCertificateFailure occurs when a certificate cannot be generated.
func (*ErrGenerateCertificateFailure) Code ¶ added in v0.1.5
func (e *ErrGenerateCertificateFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateCertificateFailure) Error ¶ added in v0.1.5
func (e *ErrGenerateCertificateFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateCertificateFailure) InternalError ¶ added in v0.1.9
func (e *ErrGenerateCertificateFailure) InternalError() error
InternalError the internal standard error object if there is one or nil if none is set.
type ErrGenerateCipherFailure ¶ added in v0.1.5
type ErrGenerateCipherFailure struct {
Err error
}
ErrGenerateCipherFailure occurs when creation of a new cipher fails.
func (*ErrGenerateCipherFailure) Code ¶ added in v0.1.5
func (e *ErrGenerateCipherFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateCipherFailure) Error ¶ added in v0.1.5
func (e *ErrGenerateCipherFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateCipherFailure) InternalError ¶ added in v0.1.9
func (e *ErrGenerateCipherFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateGCMFailure ¶ added in v0.1.5
type ErrGenerateGCMFailure struct {
Err error
}
ErrGenerateGCMFailure occurs when creation of a new GCM fails.
func (*ErrGenerateGCMFailure) Code ¶ added in v0.1.5
func (e *ErrGenerateGCMFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateGCMFailure) Error ¶ added in v0.1.5
func (e *ErrGenerateGCMFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateGCMFailure) InternalError ¶ added in v0.1.9
func (e *ErrGenerateGCMFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateIVFailure ¶ added in v0.1.5
type ErrGenerateIVFailure struct {
Err error
}
ErrGenerateIVFailure occurs when an initialization vector cannot be generated.
func (*ErrGenerateIVFailure) Code ¶ added in v0.1.5
func (e *ErrGenerateIVFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateIVFailure) Error ¶ added in v0.1.5
func (e *ErrGenerateIVFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateIVFailure) InternalError ¶ added in v0.1.9
func (e *ErrGenerateIVFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateNonceFailure ¶ added in v0.1.5
type ErrGenerateNonceFailure struct {
Err error
}
ErrGenerateNonceFailure occurs when a nonce for encryption cannot be generated.
func (*ErrGenerateNonceFailure) Code ¶ added in v0.1.5
func (e *ErrGenerateNonceFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateNonceFailure) Error ¶ added in v0.1.5
func (e *ErrGenerateNonceFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateNonceFailure) InternalError ¶ added in v0.1.9
func (e *ErrGenerateNonceFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGeneratePGPKeyFailure ¶ added in v0.1.5
ErrGeneratePGPKeyFailure occurs when a new PGP key cannot be generated.
func (*ErrGeneratePGPKeyFailure) Code ¶ added in v0.1.5
func (e *ErrGeneratePGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrGeneratePGPKeyFailure) Error ¶ added in v0.1.5
func (e *ErrGeneratePGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrGeneratePGPKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrGeneratePGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGeneratePrivateKeyFailure ¶ added in v0.1.5
type ErrGeneratePrivateKeyFailure struct {
Err error
}
ErrGeneratePrivateKeyFailure occurs when a private key for a certificate cannot be generated.
func (*ErrGeneratePrivateKeyFailure) Code ¶ added in v0.1.5
func (e *ErrGeneratePrivateKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrGeneratePrivateKeyFailure) Error ¶ added in v0.1.5
func (e *ErrGeneratePrivateKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrGeneratePrivateKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrGeneratePrivateKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateRandomKeyFailure ¶ added in v0.1.5
type ErrGenerateRandomKeyFailure struct {
Err error
}
ErrGenerateRandomKeyFailure occurs when a random encryption key cannot be generated.
func (*ErrGenerateRandomKeyFailure) Code ¶ added in v0.1.5
func (e *ErrGenerateRandomKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateRandomKeyFailure) Error ¶ added in v0.1.5
func (e *ErrGenerateRandomKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateRandomKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrGenerateRandomKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGetPGPKeyFailure ¶ added in v0.1.5
type ErrGetPGPKeyFailure struct {
Err error
}
ErrGetPGPKeyFailure occurs when a PGP key cannot be retrieved.
func (*ErrGetPGPKeyFailure) Code ¶ added in v0.1.5
func (e *ErrGetPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrGetPGPKeyFailure) Error ¶ added in v0.1.5
func (e *ErrGetPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrGetPGPKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrGetPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrInvalidCertificate ¶ added in v0.1.5
ErrInvalidCertificate occurs when a certificate cannot be validated.
func (*ErrInvalidCertificate) Code ¶ added in v0.1.5
func (e *ErrInvalidCertificate) Code() int
Code returns the corresponding error code.
func (*ErrInvalidCertificate) Error ¶ added in v0.1.5
func (e *ErrInvalidCertificate) Error() string
Error returns the string version of the error.
func (*ErrInvalidCertificate) InternalError ¶ added in v0.1.9
func (e *ErrInvalidCertificate) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrInvalidSignature ¶ added in v0.1.5
type ErrInvalidSignature struct {
Err error
}
ErrInvalidSignature occurs when the signature for a block of data is invalid.
func (*ErrInvalidSignature) Code ¶ added in v0.1.5
func (e *ErrInvalidSignature) Code() int
Code returns the corresponding error code.
func (*ErrInvalidSignature) Error ¶ added in v0.1.5
func (e *ErrInvalidSignature) Error() string
Error returns the string version of the error.
func (*ErrInvalidSignature) InternalError ¶ added in v0.1.9
func (e *ErrInvalidSignature) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrInvalidTokenClaims ¶ added in v0.1.5
type ErrInvalidTokenClaims struct {
Err error
}
ErrInvalidTokenClaims occurs when a token is signed with one algorithm but a different algorithm was expected.
func (*ErrInvalidTokenClaims) Code ¶ added in v0.1.5
func (e *ErrInvalidTokenClaims) Code() int
Code returns the corresponding error code.
func (*ErrInvalidTokenClaims) Error ¶ added in v0.1.5
func (e *ErrInvalidTokenClaims) Error() string
Error returns the string version of the error.
func (*ErrInvalidTokenClaims) InternalError ¶ added in v0.1.9
func (e *ErrInvalidTokenClaims) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrInvalidTokenSignatureAlgorithm ¶ added in v0.1.5
type ErrInvalidTokenSignatureAlgorithm struct { Alg interface{} Expected string }
ErrInvalidTokenSignatureAlgorithm occurs when a token is signed with one algorithm but a different algorithm was expected.
func (*ErrInvalidTokenSignatureAlgorithm) Code ¶ added in v0.1.5
func (e *ErrInvalidTokenSignatureAlgorithm) Code() int
Code returns the corresponding error code.
func (*ErrInvalidTokenSignatureAlgorithm) Error ¶ added in v0.1.5
func (e *ErrInvalidTokenSignatureAlgorithm) Error() string
Error returns the string version of the error.
func (*ErrInvalidTokenSignatureAlgorithm) InternalError ¶ added in v0.1.9
func (e *ErrInvalidTokenSignatureAlgorithm) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrLoadCertificateFailure ¶ added in v0.1.5
type ErrLoadCertificateFailure struct {
Err error
}
ErrLoadCertificateFailure occurs when one or more certificates cannot be loaded.
func (*ErrLoadCertificateFailure) Code ¶ added in v0.1.5
func (e *ErrLoadCertificateFailure) Code() int
Code returns the corresponding error code.
func (*ErrLoadCertificateFailure) Error ¶ added in v0.1.5
func (e *ErrLoadCertificateFailure) Error() string
Error returns the string version of the error.
func (*ErrLoadCertificateFailure) InternalError ¶ added in v0.1.9
func (e *ErrLoadCertificateFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrLoadPGPKeyFailure ¶ added in v0.1.5
type ErrLoadPGPKeyFailure struct {
Err error
}
ErrLoadPGPKeyFailure occurs when a PGP key cannot be loaded.
func (*ErrLoadPGPKeyFailure) Code ¶ added in v0.1.5
func (e *ErrLoadPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrLoadPGPKeyFailure) Error ¶ added in v0.1.5
func (e *ErrLoadPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrLoadPGPKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrLoadPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrLockPGPKeyFailure ¶ added in v0.1.5
ErrLockPGPKeyFailure occurs when a PGP key cannot be locked.
func (*ErrLockPGPKeyFailure) Code ¶ added in v0.1.5
func (e *ErrLockPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrLockPGPKeyFailure) Error ¶ added in v0.1.5
func (e *ErrLockPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrLockPGPKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrLockPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrParseCertificateFailure ¶ added in v0.1.5
type ErrParseCertificateFailure struct {
Err error
}
ErrParseCertificateFailure occurs when one or more certificates cannot be parsed
func (*ErrParseCertificateFailure) Code ¶ added in v0.1.5
func (e *ErrParseCertificateFailure) Code() int
Code returns the corresponding error code.
func (*ErrParseCertificateFailure) Error ¶ added in v0.1.5
func (e *ErrParseCertificateFailure) Error() string
Error returns the string version of the error.
func (*ErrParseCertificateFailure) InternalError ¶ added in v0.1.9
func (e *ErrParseCertificateFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrParseJWTTokenFailure ¶ added in v0.3.7
type ErrParseJWTTokenFailure struct {
Err error
}
ErrParseJWTTokenFailure occurs when a token cannot be parsed or is invalid.
func (*ErrParseJWTTokenFailure) Code ¶ added in v0.3.7
func (e *ErrParseJWTTokenFailure) Code() int
Code returns the corresponding error code.
func (*ErrParseJWTTokenFailure) Error ¶ added in v0.3.7
func (e *ErrParseJWTTokenFailure) Error() string
Error returns the string version of the error.
func (*ErrParseJWTTokenFailure) InternalError ¶ added in v0.3.7
func (e *ErrParseJWTTokenFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrReadFileFailure ¶ added in v0.1.5
ErrReadFileFailure occurs when there is an error reading a file.
func (*ErrReadFileFailure) Code ¶ added in v0.1.5
func (e *ErrReadFileFailure) Code() int
Code returns the corresponding error code.
func (*ErrReadFileFailure) Error ¶ added in v0.1.5
func (e *ErrReadFileFailure) Error() string
Error returns the string version of the error.
func (*ErrReadFileFailure) InternalError ¶ added in v0.1.9
func (e *ErrReadFileFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrSignDataFailure ¶ added in v0.1.5
type ErrSignDataFailure struct {
Err error
}
ErrSignDataFailure occurs when signing data with a private key fails.
func (*ErrSignDataFailure) Code ¶ added in v0.1.5
func (e *ErrSignDataFailure) Code() int
Code returns the corresponding error code.
func (*ErrSignDataFailure) Error ¶ added in v0.1.5
func (e *ErrSignDataFailure) Error() string
Error returns the string version of the error.
func (*ErrSignDataFailure) InternalError ¶ added in v0.1.9
func (e *ErrSignDataFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrSignJWTTokenFailure ¶ added in v0.1.5
type ErrSignJWTTokenFailure struct {
Err error
}
ErrSignJWTTokenFailure occurs when a failure occurs while signing a token.
func (*ErrSignJWTTokenFailure) Code ¶ added in v0.1.5
func (e *ErrSignJWTTokenFailure) Code() int
Code returns the corresponding error code.
func (*ErrSignJWTTokenFailure) Error ¶ added in v0.1.5
func (e *ErrSignJWTTokenFailure) Error() string
Error returns the string version of the error.
func (*ErrSignJWTTokenFailure) InternalError ¶ added in v0.1.9
func (e *ErrSignJWTTokenFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrUnlockPGPKeyFailure ¶ added in v0.1.5
type ErrUnlockPGPKeyFailure struct {
Err error
}
ErrUnlockPGPKeyFailure occurs when a PGP key cannot be unlocked.
func (*ErrUnlockPGPKeyFailure) Code ¶ added in v0.1.5
func (e *ErrUnlockPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrUnlockPGPKeyFailure) Error ¶ added in v0.1.5
func (e *ErrUnlockPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrUnlockPGPKeyFailure) InternalError ¶ added in v0.1.9
func (e *ErrUnlockPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type JWTAuthECDSAService ¶ added in v0.1.5
type JWTAuthECDSAService struct {
// contains filtered or unexported fields
}
JWTAuthECDSAService creates and validates JWT tokens that are signed with a private ECDSA key and validated with a public ECDSA key.
You must use the same key pair to validate the JWT token as was used to generate it. Otherwise, validation will fail.
func NewJWTAuthECDSAService ¶ added in v0.1.5
func NewJWTAuthECDSAService(publicKey *ecdsa.PublicKey, privateKey *ecdsa.PrivateKey) *JWTAuthECDSAService
NewJWTAuthECDSAService creates an initializes a new service object.
func (*JWTAuthECDSAService) GenerateToken ¶ added in v0.1.5
func (j *JWTAuthECDSAService) GenerateToken(claims jwt.Claims, ctx context.Context) (string, error)
GenerateToken generates a new JWT token with the given claims.
The following errors are returned by this function: ErrSignJWTTokenFailure
func (*JWTAuthECDSAService) VerifyToken ¶ added in v0.3.6
func (j *JWTAuthECDSAService) VerifyToken(encodedToken string, ctx context.Context) (*jwt.Token, error)
VerifyToken parses and verifies the token string, returning the resulting JWT token for further validation.
The following errors are returned by this function: ErrInvalidTokenSignatureAlgorithm, ErrParseJWTTokenFailure
type JWTAuthHMACService ¶ added in v0.1.5
type JWTAuthHMACService struct {
// contains filtered or unexported fields
}
JWTAuthHMACService creates and validates JWT tokens that are signed with an HMAC256-hashed secret.
You must use the same validate the JWT token as was used to generate it. Otherwise, validation will fail.
func NewJWTAuthHMACService ¶ added in v0.1.5
func NewJWTAuthHMACService(secret []byte) *JWTAuthHMACService
NewJWTAuthHMACService creates an initializes a new service object.
func (*JWTAuthHMACService) GenerateToken ¶ added in v0.1.5
func (j *JWTAuthHMACService) GenerateToken(claims jwt.Claims, ctx context.Context) (string, error)
GenerateToken generates a new JWT token with the given claims.
The following errors are returned by this function: ErrSignJWTTokenFailure
func (*JWTAuthHMACService) VerifyToken ¶ added in v0.3.6
func (j *JWTAuthHMACService) VerifyToken(encodedToken string, ctx context.Context) (*jwt.Token, error)
VerifyToken parses and verifies the token string, returning the resulting JWT token for further validation.
The following errors are returned by this function: ErrInvalidTokenSignatureAlgorithm, ErrParseJWTTokenFailure
type JWTAuthRSAService ¶ added in v0.1.5
type JWTAuthRSAService struct {
// contains filtered or unexported fields
}
JWTAuthRSAService creates and validates JWT tokens that are signed with a private RSA key and validated with a public RSA key.
You must use the same key pair to validate the JWT token as was used to generate it. Otherwise, validation will fail.
func NewJWTAuthRSAService ¶ added in v0.1.5
func NewJWTAuthRSAService(publicKey *rsa.PublicKey, privateKey *rsa.PrivateKey) *JWTAuthRSAService
NewJWTAuthRSAService creates an initializes a new service object.
func (*JWTAuthRSAService) GenerateToken ¶ added in v0.1.5
func (j *JWTAuthRSAService) GenerateToken(claims jwt.Claims, ctx context.Context) (string, error)
GenerateToken generates a new JWT token with the given claims.
The following errors are returned by this function: ErrSignJWTTokenFailure
func (*JWTAuthRSAService) VerifyToken ¶ added in v0.3.6
func (j *JWTAuthRSAService) VerifyToken(encodedToken string, ctx context.Context) (*jwt.Token, error)
VerifyToken parses and verifies the token string, returning the resulting JWT token for further validation.
The following errors are returned by this function: ErrInvalidTokenSignatureAlgorithm, ErrParseJWTTokenFailure
type JWTAuthService ¶ added in v0.1.5
type JWTAuthService interface { // GenerateToken should generate a new JWT token with the given claims and return the encoded JWT token. GenerateToken(jwt.Claims, context.Context) (string, error) // VerifyToken should parse and verify the token string and return the resulting JWT token for further validation. VerifyToken(string, context.Context) (*jwt.Token, error) }
JWTAuthService represents any object that is able to generate new JWT tokens and also validate them.
type PEMCipher ¶
type PEMCipher int
PEMCipher is just an alias for int.
const ( PEMCipherDES PEMCipher PEMCipher3DES PEMCipherAES128 PEMCipherAES192 PEMCipherAES256 )
Possible values for the EncryptPEMBlock encryption algorithm.
type PGPKeyPair ¶
type PGPKeyPair struct {
// contains filtered or unexported fields
}
PGPKeyPair represents a PGP key pair.
func NewPGPKeyPair ¶
NewPGPKeyPair returns a new PGP key pair.
Be sure to call ClearPrivateParams on the returned key to clear memory out when finished with the object.
The following errors are returned by this function: ErrGeneratePGPKeyFailure, ErrLockPGPKeyFailure, ErrPGPArmorKeyFailure
func NewPGPKeyPairFromArmor ¶
func NewPGPKeyPairFromArmor(armoredKey, passphrase string, ctx context.Context) (*PGPKeyPair, error)
NewPGPKeyPairFromArmor returns a new PGP key pair from the given armored private key.
Be sure to call ClearPrivateParams on the returned key to clear memory out when finished with the object.
The following errors are returned by this function: ErrLoadPGPKeyFailure, ErrUnlockPGPKeyFailure
func (*PGPKeyPair) ClearPrivateParams ¶
func (kp *PGPKeyPair) ClearPrivateParams()
ClearPrivateParams clears out memory attached to the private key.
func (*PGPKeyPair) GetArmoredPrivateKey ¶
func (kp *PGPKeyPair) GetArmoredPrivateKey(ctx context.Context) (string, error)
ArmoredPrivateKey returns the private key wrapped in PGP armor.
The following errors are returned by this function: ErrGetPGPKeyFailure
func (*PGPKeyPair) GetArmoredPublicKey ¶
func (kp *PGPKeyPair) GetArmoredPublicKey(ctx context.Context) (string, error)
ArmoredPublicKey returns the public key wrapped in PGP armor.
The following errors are returned by this function: ErrGetPGPKeyFailure