Documentation ¶
Overview ¶
Package crypto contains functionality for dealing with X509 certificates and cryptography.
Index ¶
- Constants
- func DecodePEMBlockFromFile(ctx context.Context, file string) (*pem.Block, error)
- func DecryptPEMBlock(ctx context.Context, b *pem.Block, password []byte) ([]byte, error)
- func DecryptString(ctx context.Context, ciphertext, key string) (string, error)
- func EncryptPEMBlock(ctx context.Context, rand io.Reader, blockType string, data, password []byte, ...) (*pem.Block, error)
- func EncryptString(ctx context.Context, plaintext, key string) (string, error)
- func GeneratePassword(passwordLength, minSpecialChar, minNum, minUpperCase int) string
- func IsEncryptedPEMBlock(b *pem.Block) bool
- func NewSelfSignedCertificateKeyPair(ctx context.Context, template *x509.Certificate, keyBits int) ([]byte, []byte, error)
- func ParsePEMCertificateBytes(ctx context.Context, contents []byte) ([]*x509.Certificate, error)
- func ParsePEMCertificateFile(ctx context.Context, file string) ([]*x509.Certificate, error)
- func ParsePEMPrivateKeyBytes(ctx context.Context, contents []byte, password []byte) (*rsa.PrivateKey, error)
- func ParsePEMPrivateKeyFile(ctx context.Context, file string, password []byte) (*rsa.PrivateKey, error)
- func ParsePublicKeyFromCertificate(ctx context.Context, cert *x509.Certificate) (*rsa.PublicKey, error)
- func Sign(ctx context.Context, contents []byte, privateKey *rsa.PrivateKey) ([]byte, error)
- func ValidateCertificate(ctx context.Context, cert *x509.Certificate, roots *CertificatePool, ...) error
- func Verify(ctx context.Context, contents, signature []byte, publicKey *rsa.PublicKey) 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(ctx context.Context, rand io.Reader, blockType string, data, password []byte, alg PEMCipher) ( *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(ctx context.Context, template *x509.Certificate, keyBits int) ( []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(ctx context.Context, contents []byte, password []byte) (*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(ctx context.Context, file string, password []byte) (*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(ctx context.Context, cert *x509.Certificate) (*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(ctx context.Context, cert *x509.Certificate, roots *CertificatePool, intermediates *CertificatePool, keyUsages []x509.ExtKeyUsage, cn string) 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(ctx context.Context, emptyPool bool) (*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(ctx context.Context, file string) 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 ¶
ErrArmorPGPKeyFailure occurs when a PGP key cannot be wrapped in armor.
func (*ErrArmorPGPKeyFailure) Code ¶
func (e *ErrArmorPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrArmorPGPKeyFailure) Error ¶
func (e *ErrArmorPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrArmorPGPKeyFailure) InternalError ¶
func (e *ErrArmorPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrDecodeFailure ¶
type ErrDecodeFailure struct {
Err error
}
ErrDecodeFailure occurs when encoded data cannot be decoded.
func (*ErrDecodeFailure) Code ¶
func (e *ErrDecodeFailure) Code() int
Code returns the corresponding error code.
func (*ErrDecodeFailure) Error ¶
func (e *ErrDecodeFailure) Error() string
Error returns the string version of the error.
func (*ErrDecodeFailure) InternalError ¶
func (e *ErrDecodeFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrDecryptFailure ¶
type ErrDecryptFailure struct {
Err error
}
ErrDecryptFailure occurs when data cannot be decrypted.
func (*ErrDecryptFailure) Code ¶
func (e *ErrDecryptFailure) Code() int
Code returns the corresponding error code.
func (*ErrDecryptFailure) Error ¶
func (e *ErrDecryptFailure) Error() string
Error returns the string version of the error.
func (*ErrDecryptFailure) InternalError ¶
func (e *ErrDecryptFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrEncodeFailure ¶
type ErrEncodeFailure struct {
Err error
}
ErrEncodeFailure occurs when data cannot be encoded.
func (*ErrEncodeFailure) Code ¶
func (e *ErrEncodeFailure) Code() int
Code returns the corresponding error code.
func (*ErrEncodeFailure) Error ¶
func (e *ErrEncodeFailure) Error() string
Error returns the string version of the error.
func (*ErrEncodeFailure) InternalError ¶
func (e *ErrEncodeFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrEncryptFailure ¶
type ErrEncryptFailure struct {
Err error
}
ErrEncryptFailure occurs when data fails to be encrypted.
func (*ErrEncryptFailure) Code ¶
func (e *ErrEncryptFailure) Code() int
Code returns the corresponding error code.
func (*ErrEncryptFailure) Error ¶
func (e *ErrEncryptFailure) Error() string
Error returns the string version of the error.
func (*ErrEncryptFailure) InternalError ¶
func (e *ErrEncryptFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrExtractPublicKeyFailure ¶
type ErrExtractPublicKeyFailure struct {
Err error
}
ErrExtractPublicKeyFailure occurs when the public key cannot be extracted from an X509 certificate.
func (*ErrExtractPublicKeyFailure) Code ¶
func (e *ErrExtractPublicKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrExtractPublicKeyFailure) Error ¶
func (e *ErrExtractPublicKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrExtractPublicKeyFailure) InternalError ¶
func (e *ErrExtractPublicKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateCertificateFailure ¶
type ErrGenerateCertificateFailure struct {
Err error
}
ErrGenerateCertificateFailure occurs when a certificate cannot be generated.
func (*ErrGenerateCertificateFailure) Code ¶
func (e *ErrGenerateCertificateFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateCertificateFailure) Error ¶
func (e *ErrGenerateCertificateFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateCertificateFailure) InternalError ¶
func (e *ErrGenerateCertificateFailure) InternalError() error
InternalError the internal standard error object if there is one or nil if none is set.
type ErrGenerateCipherFailure ¶
type ErrGenerateCipherFailure struct {
Err error
}
ErrGenerateCipherFailure occurs when creation of a new cipher fails.
func (*ErrGenerateCipherFailure) Code ¶
func (e *ErrGenerateCipherFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateCipherFailure) Error ¶
func (e *ErrGenerateCipherFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateCipherFailure) InternalError ¶
func (e *ErrGenerateCipherFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateGCMFailure ¶
type ErrGenerateGCMFailure struct {
Err error
}
ErrGenerateGCMFailure occurs when creation of a new GCM fails.
func (*ErrGenerateGCMFailure) Code ¶
func (e *ErrGenerateGCMFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateGCMFailure) Error ¶
func (e *ErrGenerateGCMFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateGCMFailure) InternalError ¶
func (e *ErrGenerateGCMFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateIVFailure ¶
type ErrGenerateIVFailure struct {
Err error
}
ErrGenerateIVFailure occurs when an initialization vector cannot be generated.
func (*ErrGenerateIVFailure) Code ¶
func (e *ErrGenerateIVFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateIVFailure) Error ¶
func (e *ErrGenerateIVFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateIVFailure) InternalError ¶
func (e *ErrGenerateIVFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateNonceFailure ¶
type ErrGenerateNonceFailure struct {
Err error
}
ErrGenerateNonceFailure occurs when a nonce for encryption cannot be generated.
func (*ErrGenerateNonceFailure) Code ¶
func (e *ErrGenerateNonceFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateNonceFailure) Error ¶
func (e *ErrGenerateNonceFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateNonceFailure) InternalError ¶
func (e *ErrGenerateNonceFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGeneratePGPKeyFailure ¶
ErrGeneratePGPKeyFailure occurs when a new PGP key cannot be generated.
func (*ErrGeneratePGPKeyFailure) Code ¶
func (e *ErrGeneratePGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrGeneratePGPKeyFailure) Error ¶
func (e *ErrGeneratePGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrGeneratePGPKeyFailure) InternalError ¶
func (e *ErrGeneratePGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGeneratePrivateKeyFailure ¶
type ErrGeneratePrivateKeyFailure struct {
Err error
}
ErrGeneratePrivateKeyFailure occurs when a private key for a certificate cannot be generated.
func (*ErrGeneratePrivateKeyFailure) Code ¶
func (e *ErrGeneratePrivateKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrGeneratePrivateKeyFailure) Error ¶
func (e *ErrGeneratePrivateKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrGeneratePrivateKeyFailure) InternalError ¶
func (e *ErrGeneratePrivateKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGenerateRandomKeyFailure ¶
type ErrGenerateRandomKeyFailure struct {
Err error
}
ErrGenerateRandomKeyFailure occurs when a random encryption key cannot be generated.
func (*ErrGenerateRandomKeyFailure) Code ¶
func (e *ErrGenerateRandomKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrGenerateRandomKeyFailure) Error ¶
func (e *ErrGenerateRandomKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrGenerateRandomKeyFailure) InternalError ¶
func (e *ErrGenerateRandomKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrGetPGPKeyFailure ¶
type ErrGetPGPKeyFailure struct {
Err error
}
ErrGetPGPKeyFailure occurs when a PGP key cannot be retrieved.
func (*ErrGetPGPKeyFailure) Code ¶
func (e *ErrGetPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrGetPGPKeyFailure) Error ¶
func (e *ErrGetPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrGetPGPKeyFailure) InternalError ¶
func (e *ErrGetPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrInvalidCertificate ¶
ErrInvalidCertificate occurs when a certificate cannot be validated.
func (*ErrInvalidCertificate) Code ¶
func (e *ErrInvalidCertificate) Code() int
Code returns the corresponding error code.
func (*ErrInvalidCertificate) Error ¶
func (e *ErrInvalidCertificate) Error() string
Error returns the string version of the error.
func (*ErrInvalidCertificate) InternalError ¶
func (e *ErrInvalidCertificate) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrInvalidSignature ¶
type ErrInvalidSignature struct {
Err error
}
ErrInvalidSignature occurs when the signature for a block of data is invalid.
func (*ErrInvalidSignature) Code ¶
func (e *ErrInvalidSignature) Code() int
Code returns the corresponding error code.
func (*ErrInvalidSignature) Error ¶
func (e *ErrInvalidSignature) Error() string
Error returns the string version of the error.
func (*ErrInvalidSignature) InternalError ¶
func (e *ErrInvalidSignature) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrInvalidTokenClaims ¶
type ErrInvalidTokenClaims struct {
Err error
}
ErrInvalidTokenClaims occurs when a token is signed with one algorithm but a different algorithm was expected.
func (*ErrInvalidTokenClaims) Code ¶
func (e *ErrInvalidTokenClaims) Code() int
Code returns the corresponding error code.
func (*ErrInvalidTokenClaims) Error ¶
func (e *ErrInvalidTokenClaims) Error() string
Error returns the string version of the error.
func (*ErrInvalidTokenClaims) InternalError ¶
func (e *ErrInvalidTokenClaims) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrInvalidTokenSignatureAlgorithm ¶
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 ¶
func (e *ErrInvalidTokenSignatureAlgorithm) Code() int
Code returns the corresponding error code.
func (*ErrInvalidTokenSignatureAlgorithm) Error ¶
func (e *ErrInvalidTokenSignatureAlgorithm) Error() string
Error returns the string version of the error.
func (*ErrInvalidTokenSignatureAlgorithm) InternalError ¶
func (e *ErrInvalidTokenSignatureAlgorithm) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrLoadCertificateFailure ¶
type ErrLoadCertificateFailure struct {
Err error
}
ErrLoadCertificateFailure occurs when one or more certificates cannot be loaded.
func (*ErrLoadCertificateFailure) Code ¶
func (e *ErrLoadCertificateFailure) Code() int
Code returns the corresponding error code.
func (*ErrLoadCertificateFailure) Error ¶
func (e *ErrLoadCertificateFailure) Error() string
Error returns the string version of the error.
func (*ErrLoadCertificateFailure) InternalError ¶
func (e *ErrLoadCertificateFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrLoadPGPKeyFailure ¶
type ErrLoadPGPKeyFailure struct {
Err error
}
ErrLoadPGPKeyFailure occurs when a PGP key cannot be loaded.
func (*ErrLoadPGPKeyFailure) Code ¶
func (e *ErrLoadPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrLoadPGPKeyFailure) Error ¶
func (e *ErrLoadPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrLoadPGPKeyFailure) InternalError ¶
func (e *ErrLoadPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrLockPGPKeyFailure ¶
ErrLockPGPKeyFailure occurs when a PGP key cannot be locked.
func (*ErrLockPGPKeyFailure) Code ¶
func (e *ErrLockPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrLockPGPKeyFailure) Error ¶
func (e *ErrLockPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrLockPGPKeyFailure) InternalError ¶
func (e *ErrLockPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrParseCertificateFailure ¶
type ErrParseCertificateFailure struct {
Err error
}
ErrParseCertificateFailure occurs when one or more certificates cannot be parsed
func (*ErrParseCertificateFailure) Code ¶
func (e *ErrParseCertificateFailure) Code() int
Code returns the corresponding error code.
func (*ErrParseCertificateFailure) Error ¶
func (e *ErrParseCertificateFailure) Error() string
Error returns the string version of the error.
func (*ErrParseCertificateFailure) InternalError ¶
func (e *ErrParseCertificateFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrParseJWTTokenFailure ¶
type ErrParseJWTTokenFailure struct {
Err error
}
ErrParseJWTTokenFailure occurs when a token cannot be parsed or is invalid.
func (*ErrParseJWTTokenFailure) Code ¶
func (e *ErrParseJWTTokenFailure) Code() int
Code returns the corresponding error code.
func (*ErrParseJWTTokenFailure) Error ¶
func (e *ErrParseJWTTokenFailure) Error() string
Error returns the string version of the error.
func (*ErrParseJWTTokenFailure) InternalError ¶
func (e *ErrParseJWTTokenFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrReadFileFailure ¶
ErrReadFileFailure occurs when there is an error reading a file.
func (*ErrReadFileFailure) Code ¶
func (e *ErrReadFileFailure) Code() int
Code returns the corresponding error code.
func (*ErrReadFileFailure) Error ¶
func (e *ErrReadFileFailure) Error() string
Error returns the string version of the error.
func (*ErrReadFileFailure) InternalError ¶
func (e *ErrReadFileFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrSignDataFailure ¶
type ErrSignDataFailure struct {
Err error
}
ErrSignDataFailure occurs when signing data with a private key fails.
func (*ErrSignDataFailure) Code ¶
func (e *ErrSignDataFailure) Code() int
Code returns the corresponding error code.
func (*ErrSignDataFailure) Error ¶
func (e *ErrSignDataFailure) Error() string
Error returns the string version of the error.
func (*ErrSignDataFailure) InternalError ¶
func (e *ErrSignDataFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrSignJWTTokenFailure ¶
type ErrSignJWTTokenFailure struct {
Err error
}
ErrSignJWTTokenFailure occurs when a failure occurs while signing a token.
func (*ErrSignJWTTokenFailure) Code ¶
func (e *ErrSignJWTTokenFailure) Code() int
Code returns the corresponding error code.
func (*ErrSignJWTTokenFailure) Error ¶
func (e *ErrSignJWTTokenFailure) Error() string
Error returns the string version of the error.
func (*ErrSignJWTTokenFailure) InternalError ¶
func (e *ErrSignJWTTokenFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type ErrUnlockPGPKeyFailure ¶
type ErrUnlockPGPKeyFailure struct {
Err error
}
ErrUnlockPGPKeyFailure occurs when a PGP key cannot be unlocked.
func (*ErrUnlockPGPKeyFailure) Code ¶
func (e *ErrUnlockPGPKeyFailure) Code() int
Code returns the corresponding error code.
func (*ErrUnlockPGPKeyFailure) Error ¶
func (e *ErrUnlockPGPKeyFailure) Error() string
Error returns the string version of the error.
func (*ErrUnlockPGPKeyFailure) InternalError ¶
func (e *ErrUnlockPGPKeyFailure) InternalError() error
InternalError returns the internal standard error object if there is one or nil if none is set.
type JWTAuthECDSAService ¶
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 ¶
func NewJWTAuthECDSAService(publicKey *ecdsa.PublicKey, privateKey *ecdsa.PrivateKey) *JWTAuthECDSAService
NewJWTAuthECDSAService creates an initializes a new service object.
func (*JWTAuthECDSAService) GenerateToken ¶
func (j *JWTAuthECDSAService) GenerateToken(ctx context.Context, claims jwt.Claims) (string, error)
GenerateToken generates a new JWT token with the given claims.
The following errors are returned by this function: ErrSignJWTTokenFailure
func (*JWTAuthECDSAService) VerifyToken ¶
func (j *JWTAuthECDSAService) VerifyToken(ctx context.Context, encodedToken string) (*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 ¶
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 ¶
func NewJWTAuthHMACService(secret []byte) *JWTAuthHMACService
NewJWTAuthHMACService creates an initializes a new service object.
func (*JWTAuthHMACService) GenerateToken ¶
func (j *JWTAuthHMACService) GenerateToken(ctx context.Context, claims jwt.Claims) (string, error)
GenerateToken generates a new JWT token with the given claims.
The following errors are returned by this function: ErrSignJWTTokenFailure
func (*JWTAuthHMACService) VerifyToken ¶
func (j *JWTAuthHMACService) VerifyToken(ctx context.Context, encodedToken string) (*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 ¶
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 ¶
func NewJWTAuthRSAService(publicKey *rsa.PublicKey, privateKey *rsa.PrivateKey) *JWTAuthRSAService
NewJWTAuthRSAService creates an initializes a new service object.
func (*JWTAuthRSAService) GenerateToken ¶
func (j *JWTAuthRSAService) GenerateToken(ctx context.Context, claims jwt.Claims) (string, error)
GenerateToken generates a new JWT token with the given claims.
The following errors are returned by this function: ErrSignJWTTokenFailure
func (*JWTAuthRSAService) VerifyToken ¶
func (j *JWTAuthRSAService) VerifyToken(ctx context.Context, encodedToken string) (*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 ¶
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(ctx context.Context, armoredKey, passphrase string) (*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)
GetArmoredPrivateKey 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)
GetArmoredPublicKey returns the public key wrapped in PGP armor.
The following errors are returned by this function: ErrGetPGPKeyFailure