LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package x509 | 5 package x509 |
6 | 6 |
7 import ( | 7 import ( |
8 "crypto/rsa" | 8 "crypto/rsa" |
9 "encoding/asn1" | 9 "encoding/asn1" |
10 "errors" | 10 "errors" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // We ignore these values because rsa will calculate them. | 33 // We ignore these values because rsa will calculate them. |
34 Exp *big.Int | 34 Exp *big.Int |
35 Coeff *big.Int | 35 Coeff *big.Int |
36 } | 36 } |
37 | 37 |
38 // ParsePKCS1PrivateKey returns an RSA private key from its ASN.1 PKCS#1 DER enc
oded form. | 38 // ParsePKCS1PrivateKey returns an RSA private key from its ASN.1 PKCS#1 DER enc
oded form. |
39 func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err error) { | 39 func ParsePKCS1PrivateKey(der []byte) (key *rsa.PrivateKey, err error) { |
40 var priv pkcs1PrivateKey | 40 var priv pkcs1PrivateKey |
41 rest, err := asn1.Unmarshal(der, &priv) | 41 rest, err := asn1.Unmarshal(der, &priv) |
42 if len(rest) > 0 { | 42 if len(rest) > 0 { |
43 » » err = asn1.SyntaxError{"trailing data"} | 43 » » err = asn1.SyntaxError{Msg: "trailing data"} |
44 return | 44 return |
45 } | 45 } |
46 if err != nil { | 46 if err != nil { |
47 return | 47 return |
48 } | 48 } |
49 | 49 |
50 if priv.Version > 1 { | 50 if priv.Version > 1 { |
51 return nil, errors.New("x509: unsupported private key version") | 51 return nil, errors.New("x509: unsupported private key version") |
52 } | 52 } |
53 | 53 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 113 |
114 b, _ := asn1.Marshal(priv) | 114 b, _ := asn1.Marshal(priv) |
115 return b | 115 return b |
116 } | 116 } |
117 | 117 |
118 // rsaPublicKey reflects the ASN.1 structure of a PKCS#1 public key. | 118 // rsaPublicKey reflects the ASN.1 structure of a PKCS#1 public key. |
119 type rsaPublicKey struct { | 119 type rsaPublicKey struct { |
120 N *big.Int | 120 N *big.Int |
121 E int | 121 E int |
122 } | 122 } |
LEFT | RIGHT |