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

Version Path
ruby_snowflake_client-1.3.7 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.3.6 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.3.5 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.3.4 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.3.4.pre.debug ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.3.3.pre.debug ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.3.2 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.3.1 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.3.0 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.2.1 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.2.0 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.1.1 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.1.0 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.0.2 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.0.1 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go
ruby_snowflake_client-1.0.0 ext/vendor/github.com/dvsekhvalnov/jose2go/hmac_using_sha.go