From 301d931ad76c0754e58cf024b46bebe685faafc5 Mon Sep 17 00:00:00 2001 From: Gibheer Date: Wed, 25 Mar 2015 20:36:21 +0100 Subject: reformat everything with gofmt Yes, I know that this will more or less destroy the history, but it had to be done. I also adjusted my editor to use gofmt rules by default now. --- rsa.go | 70 ++++++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'rsa.go') diff --git a/rsa.go b/rsa.go index bcdfe6e..11a770b 100644 --- a/rsa.go +++ b/rsa.go @@ -1,76 +1,82 @@ package pki import ( - "crypto" - "crypto/rand" - "crypto/rsa" - "crypto/x509" - "encoding/pem" - "errors" - "io" + "crypto" + "crypto/rand" + "crypto/rsa" + "crypto/x509" + "encoding/pem" + "errors" + "io" ) const ( - PemLabelRsa = "RSA PRIVATE KEY" + PemLabelRsa = "RSA PRIVATE KEY" ) type ( - RsaPrivateKey struct { - private_key *rsa.PrivateKey - } + RsaPrivateKey struct { + private_key *rsa.PrivateKey + } - RsaPublicKey struct { - public_key *rsa.PublicKey - } + RsaPublicKey struct { + public_key *rsa.PublicKey + } ) // generate a new rsa private key func NewPrivateKeyRsa(size int) (*RsaPrivateKey, error) { - key, err := rsa.GenerateKey(rand.Reader, size) - if err != nil { return nil, err } - return &RsaPrivateKey{key}, nil + key, err := rsa.GenerateKey(rand.Reader, size) + if err != nil { + return nil, err + } + return &RsaPrivateKey{key}, nil } // load a rsa private key its ASN.1 presentation func LoadPrivateKeyRsa(raw []byte) (*RsaPrivateKey, error) { - key, err := x509.ParsePKCS1PrivateKey(raw) - if err != nil { return nil, err } - return &RsaPrivateKey{key}, nil + key, err := x509.ParsePKCS1PrivateKey(raw) + if err != nil { + return nil, err + } + return &RsaPrivateKey{key}, nil } func (pr *RsaPrivateKey) Public() PublicKey { - return &RsaPublicKey{pr.private_key.Public().(*rsa.PublicKey)} + return &RsaPublicKey{pr.private_key.Public().(*rsa.PublicKey)} } func (pr RsaPrivateKey) Sign(message []byte, hash crypto.Hash) ([]byte, error) { - return make([]byte, 0), errors.New("not implemented yet!") + return make([]byte, 0), errors.New("not implemented yet!") } // get the private key func (pr RsaPrivateKey) PrivateKey() crypto.PrivateKey { - return pr.private_key + return pr.private_key } func (pr RsaPrivateKey) MarshalPem() (io.WriterTo, error) { - asn1 := x509.MarshalPKCS1PrivateKey(pr.private_key) - pem_block := pem.Block{Type: PemLabelRsa, Bytes: asn1} - return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil + asn1 := x509.MarshalPKCS1PrivateKey(pr.private_key) + pem_block := pem.Block{Type: PemLabelRsa, Bytes: asn1} + return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil } // restore a rsa public key func LoadPublicKeyRsa(raw []byte) (*RsaPublicKey, error) { - return nil, errors.New("not implemented yet!") + return nil, errors.New("not implemented yet!") } // marshal a rsa public key into pem format func (pu *RsaPublicKey) MarshalPem() (io.WriterTo, error) { - asn1, err := x509.MarshalPKIXPublicKey(pu.public_key) - if err != nil { return nil, err } - pem_block := pem.Block{Type: PemLabelPublic, Bytes: asn1} - return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil + asn1, err := x509.MarshalPKIXPublicKey(pu.public_key) + if err != nil { + return nil, err + } + pem_block := pem.Block{Type: PemLabelPublic, Bytes: asn1} + return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil } // verify a message with a signature using the public key func (pu *RsaPublicKey) Verify(message []byte, signature []byte, hash crypto.Hash) (bool, error) { - return false, errors.New("not implemented yet!") + return false, errors.New("not implemented yet!") } -- cgit v1.2.3-70-g09d2