going somewhere

This commit is contained in:
didier amyot committed 2014-11-09 18:28:08 -08:00
1 parent 6b3c99664c
commit 209af0d820
16 files changed
+549 -131

No files matched your search

+35 -4
View File
@@ -1,7 +1,11 @@
package asymetric
import (
"crypto/rand"
"errors"
"github.com/didiercrunch/filou/contract"
"github.com/didiercrunch/filou/helper"
)
type PublicKeyEncryptor interface {
@@ -12,10 +16,37 @@ type Signer interface {
Sign(data []byte) ([]byte, error)
}
func GetSigner(contract_ contract.AcceptedContract) (Signer, error) {
return nil, nil
func GetSigner(contract_ *contract.AcceptedContract) (Signer, error) {
if contract_.SignatureScheme == "rsa_pss" {
return getRsaPssSignerFromContract(contract_)
}
return nil, errors.New("signature scheme " + contract_.SignatureScheme + " not supported")
}
func GetPublicKeyEncryptor(contract_ contract.AcceptedContract) (Signer, error) {
return nil, nil
func GetPublicKeyEncryptor(contract_ *contract.AcceptedContract) (PublicKeyEncryptor, error) {
if contract_.AsynchronousEncryptionScheme == "rsa_oaep" {
return getRsaOaepEncryptorFromContract(contract_)
} else {
return nil, errors.New("asynchronous encryption scheme " + contract_.AsynchronousEncryptionScheme + " not supported")
}
}
func getRsaPssSignerFromContract(con *contract.AcceptedContract) (*RsaPssSigner, error) {
if privKey, err := con.RsaPrivateKey(); err != nil {
return nil, err
} else if hash, err := helper.GetHashFunctionByLowerCaseName(con.Hash); err != nil {
return nil, err
} else {
return &RsaPssSigner{privKey, con.RsaPublicKey, hash, rand.Reader}, nil
}
}
func getRsaOaepEncryptorFromContract(con *contract.AcceptedContract) (*RsaOaepEncrypter, error) {
if privKey, err := con.RsaPrivateKey(); err != nil {
return nil, err
} else if hash, err := helper.GetHashFunctionByLowerCaseName(con.Hash); err != nil {
return nil, err
} else {
return &RsaOaepEncrypter{privKey, con.RsaPublicKey, hash, rand.Reader}, nil
}
}