aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGibheer <gibheer@gmail.com>2015-02-18 21:49:07 +0100
committerGibheer <gibheer@gmail.com>2015-02-18 21:49:07 +0100
commit53be920308432fccbdddeef248e0bebed81877ba (patch)
treedf0a5e717ae720e917aa56552e961c7eba2aa474
parent018086528ad2bcea4b0edbd9a3c3c4be1c682ef7 (diff)
add marshal support
-rw-r--r--rsa.go9
1 files changed, 6 insertions, 3 deletions
diff --git a/rsa.go b/rsa.go
index df8c8cb..c0f9986 100644
--- a/rsa.go
+++ b/rsa.go
@@ -5,6 +5,7 @@ import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
+ "encoding/pem"
"errors"
)
@@ -18,7 +19,7 @@ type (
}
RsaPublicKey struct {
- public_key rsa.PublicKey
+ public_key *rsa.PublicKey
}
)
@@ -37,7 +38,7 @@ func LoadPrivateKeyRsa(raw []byte) (*RsaPrivateKey, error) {
}
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) ([]byte, error) {
@@ -50,7 +51,9 @@ func (pr RsaPrivateKey) privateKey() crypto.PrivateKey {
}
func (pr RsaPrivateKey) MarshalPem() (marshalledPemBlock, error) {
- return nil, errors.New("not implemented yet!")
+ asn1 := x509.MarshalPKCS1PrivateKey(pr.private_key)
+ pem_block := pem.Block{Type: PemLabelRsa, Bytes: asn1}
+ return pem.EncodeToMemory(&pem_block), nil
}
func (pu *RsaPublicKey) MarshalPem() (marshalledPemBlock, error) {