Skip to content

Commit

Permalink
fix(sigchain): naming and code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Louvigny committed Aug 20, 2018
1 parent aa33d01 commit 2b07171
Show file tree
Hide file tree
Showing 9 changed files with 388 additions and 327 deletions.
54 changes: 23 additions & 31 deletions core/crypto/keypair/keypair.go
Expand Up @@ -24,38 +24,30 @@ type Interface interface {
}

func (m SignatureAlgorithm) GetHashFunction() (crypto.Hash, error) {
switch m {
case SignatureAlgorithm_MD5WithRSA:
return crypto.MD5, nil
case SignatureAlgorithm_SHA1WithRSA:
return crypto.SHA1, nil
case SignatureAlgorithm_SHA256WithRSA:
return crypto.SHA256, nil
case SignatureAlgorithm_SHA384WithRSA:
return crypto.SHA384, nil
case SignatureAlgorithm_SHA512WithRSA:
return crypto.SHA512, nil
case SignatureAlgorithm_DSAWithSHA1:
return crypto.SHA1, nil
case SignatureAlgorithm_DSAWithSHA256:
return crypto.SHA256, nil
case SignatureAlgorithm_ECDSAWithSHA1:
return crypto.SHA1, nil
case SignatureAlgorithm_ECDSAWithSHA256:
return crypto.SHA256, nil
case SignatureAlgorithm_ECDSAWithSHA384:
return crypto.SHA384, nil
case SignatureAlgorithm_ECDSAWithSHA512:
return crypto.SHA384, nil
case SignatureAlgorithm_SHA256WithRSAPSS:
return crypto.SHA256, nil
case SignatureAlgorithm_SHA384WithRSAPSS:
return crypto.SHA384, nil
case SignatureAlgorithm_SHA512WithRSAPSS:
return crypto.SHA384, nil
algorithms := map[SignatureAlgorithm]crypto.Hash{
SignatureAlgorithm_MD5_WITH_RSA: crypto.MD5,
SignatureAlgorithm_SHA1_WITH_RSA: crypto.SHA1,
SignatureAlgorithm_SHA256_WITH_RSA: crypto.SHA256,
SignatureAlgorithm_SHA384_WITH_RSA: crypto.SHA384,
SignatureAlgorithm_SHA512_WITH_RSA: crypto.SHA512,
SignatureAlgorithm_DSA_WITH_SHA1: crypto.SHA1,
SignatureAlgorithm_DSA_WITH_SHA256: crypto.SHA256,
SignatureAlgorithm_ECDSA_WITH_SHA1: crypto.SHA1,
SignatureAlgorithm_ECDSA_WITH_SHA256: crypto.SHA256,
SignatureAlgorithm_ECDSA_WITH_SHA384: crypto.SHA384,
SignatureAlgorithm_ECDSA_WITH_SHA512: crypto.SHA384,
SignatureAlgorithm_SHA256_WITH_RSAPSS: crypto.SHA256,
SignatureAlgorithm_SHA384_WITH_RSAPSS: crypto.SHA384,
SignatureAlgorithm_SHA512_WITH_RSAPSS: crypto.SHA384,
}

algorithm, ok := algorithms[m]

if ok == false {
return crypto.MD4, errors.New("unsupported hashing function")
}

return crypto.MD4, errors.New("unsupported hashing function")
return algorithm, nil
}

// GetDataToSign We need to have a predictable way to check a
Expand Down Expand Up @@ -179,7 +171,7 @@ func IntToBytes(input uint64) []byte {
return bs
}

func GetHashFuncForKey(pub interface{}) (crypto.Hash, error) {
func GetHashFuncForKey(pub crypto.PublicKey) (crypto.Hash, error) {
switch pub := pub.(type) {
case *rsa.PublicKey:
return crypto.SHA256, nil
Expand Down

0 comments on commit 2b07171

Please sign in to comment.