Sha256: bfbb822d806e7b654150abb2efcada20f133b0e00556c5d01902a6782465432e
Contents?: true
Size: 1.01 KB
Versions: 16
Compression:
Stored size: 1.01 KB
Contents
package jose import ( "crypto/hmac" "errors" ) func init() { RegisterJws(&HmacUsingSha{keySizeBits: 256}) RegisterJws(&HmacUsingSha{keySizeBits: 384}) RegisterJws(&HmacUsingSha{keySizeBits: 512}) } // HMAC with SHA signing algorithm implementation type HmacUsingSha struct{ keySizeBits int } func (alg *HmacUsingSha) Name() string { switch alg.keySizeBits { case 256: return HS256 case 384: return HS384 default: return HS512 } } func (alg *HmacUsingSha) Verify(securedInput, signature []byte, key interface{}) error { actualSig,_ := alg.Sign(securedInput, key) if !hmac.Equal(signature, actualSig) { return errors.New("HmacUsingSha.Verify(): Signature is invalid") } return nil } func (alg *HmacUsingSha) Sign(securedInput []byte, key interface{}) (signature []byte, err error) { //TODO: assert min key size if pubKey,ok:=key.([]byte); ok { return calculateHmac(alg.keySizeBits, securedInput, pubKey),nil } return nil,errors.New("HmacUsingSha.Sign(): expects key to be '[]byte' array") }
Version data entries
16 entries across 16 versions & 1 rubygems