Documentation ¶
Index ¶
- Variables
- func BuildSignatureData(req *http.Request, headers []string) []byte
- func BuildSignatureString(req *http.Request, headers []string) string
- func HMACSign(key []byte, hash crypto.Hash, data []byte) ([]byte, error)
- func HMACVerify(key []byte, hash crypto.Hash, data, sig []byte) error
- func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error)
- func RSASign(key *rsa.PrivateKey, hash crypto.Hash, data []byte) (signature []byte, err error)
- func RSAVerify(key *rsa.PublicKey, hash crypto.Hash, data, sig []byte) (err error)
- func RequireSignature(h http.Handler, v *Verifier, realm string) (out http.Handler)
- type Algorithm
- type KeyGetter
- type KeyGetterFunc
- type MemoryKeyStore
- type Params
- type Signer
- func NewHMACSHA256Signer(id string, key []byte, headers []string) (signer *Signer)
- func NewRSASHA1Signer(id string, key *rsa.PrivateKey, headers []string) (signer *Signer)
- func NewRSASHA256Signer(id string, key *rsa.PrivateKey, headers []string) (signer *Signer)
- func NewSigner(id string, key interface{}, algo Algorithm, headers []string) (signer *Signer)
- type Verifier
Constants ¶
This section is empty.
Variables ¶
var ( // Rand is a hookable reader used as a random byte source. Rand io.Reader = rand.Reader )
Functions ¶
func BuildSignatureData ¶
BuildSignatureData is a convenience wrapper around BuildSignatureString that returns []byte instead of a string.
func BuildSignatureString ¶
BuildSignatureString constructs a signature string following section 2.3
func HMACVerify ¶
HMACVerify verifies a signed digest of the data hashed using the provided hash and key.
func ParseRsaPrivateKeyFromPemStr ¶
func ParseRsaPrivateKeyFromPemStr(privPEM string) (*rsa.PrivateKey, error)
Types ¶
type Algorithm ¶
type Algorithm interface { Name() string Sign(key interface{}, data []byte) (sig []byte, err error) Verify(key interface{}, data, sig []byte) error }
Algorithm provides methods used to sign/verify signatures.
var HMACSHA256 Algorithm = hmac_sha256{}
HMACSHA256 implements keyed HMAC over SHA256 digests
var RSASHA1 Algorithm = rsa_sha1{}
RSASHA1 implements RSA PKCS1v15 signatures over a SHA1 digest
var RSASHA256 Algorithm = rsa_sha256{}
RSASHA256 implements RSA PKCS1v15 signatures over a SHA256 digest
type KeyGetter ¶
type KeyGetter interface {
GetKey(id string) interface{}
}
KeyGetter is an interface used by the verifier to retrieve a key stored by key id.
The following types are supported for the specified algorithms: []byte - HMAC signatures *rsa.PublicKey - RSA signatures *rsa.PrivateKey - RSA signatures
Other types will treated as if no key was returned.
type KeyGetterFunc ¶
type KeyGetterFunc func(id string) interface{}
KeyGetterFunc is a convenience type for implementing a KeyGetter with a regular function
func (KeyGetterFunc) GetKey ¶
func (fn KeyGetterFunc) GetKey(id string) interface{}
GetKey calls fn(id)
type MemoryKeyStore ¶
type MemoryKeyStore struct {
// contains filtered or unexported fields
}
func NewMemoryKeyStore ¶
func NewMemoryKeyStore() *MemoryKeyStore
func (*MemoryKeyStore) GetKey ¶
func (m *MemoryKeyStore) GetKey(id string) interface{}
func (*MemoryKeyStore) SetKey ¶
func (m *MemoryKeyStore) SetKey(id string, key interface{})
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
func NewHMACSHA256Signer ¶
NewHMACSHA256Signer contructs a signer with the specified key id, hmac key, and headers to sign.
func NewRSASHA1Signer ¶
func NewRSASHA1Signer(id string, key *rsa.PrivateKey, headers []string) ( signer *Signer)
NewRSASHA1Signer contructs a signer with the specified key id, rsa private key and headers to sign.
func NewRSASHA256Signer ¶
func NewRSASHA256Signer(id string, key *rsa.PrivateKey, headers []string) ( signer *Signer)
NewRSASHA256Signer contructs a signer with the specified key id, rsa private key and headers to sign.
type Verifier ¶
type Verifier struct {
// contains filtered or unexported fields
}