aboutsummaryrefslogtreecommitdiff
path: root/rsa.go
diff options
context:
space:
mode:
authorGibheer <gibheer+git@zero-knowledge.org>2017-05-12 15:27:44 +0200
committerGibheer <gibheer+git@zero-knowledge.org>2017-05-12 15:27:44 +0200
commitb6c44317f540dac8763e720767b0e73940a0b6c5 (patch)
treefac6e911056ba12da589dac4ad1f32aa63430f78 /rsa.go
parentfd88bca2872e589b451cde3767dbc59d82bd1c83 (diff)
add proper pem interface
This should finally resolve the completely broken and wrong API to get a pem representation of a resource.
Diffstat (limited to 'rsa.go')
-rw-r--r--rsa.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/rsa.go b/rsa.go
index 76296ed..7d575cb 100644
--- a/rsa.go
+++ b/rsa.go
@@ -61,11 +61,20 @@ func (pr RsaPrivateKey) PrivateKey() crypto.PrivateKey {
}
func (pr RsaPrivateKey) MarshalPem() (io.WriterTo, error) {
- asn1 := x509.MarshalPKCS1PrivateKey(pr.private_key)
- pem_block := pem.Block{Type: PemLabelRsa, Bytes: asn1}
+ pem_block, err := pr.ToPem()
+ if err != nil { // it does not currently return an error, but maybe that will change
+ return nil, err
+ }
return marshalledPemBlock(pem.EncodeToMemory(&pem_block)), nil
}
+func (pr RsaPrivateKey) ToPem() (pem.Block, error) {
+ return pem.Block{
+ Type: PemLabelRsa,
+ Bytes: x509.MarshalPKCS1PrivateKey(pr.private_key),
+ }, nil
+}
+
// restore a rsa public key
func LoadPublicKeyRsa(raw []byte) (*RsaPublicKey, error) {
pub := &RsaPublicKey{}