refactor(crypto) move proto to internal pb package
https://docs.google.com/document/d/1e8kOo3r51b2BWtTs_1uADIA5djfXhPT36s6eHVRIvaU/edit
Brian Tiger Chow committed
Oct 22, 2014 at 04:01 UTC
e3a9a11afc6049624744aab8d5f008aa1d195852
4 files changed
+13
-10
crypto/internal/pb/encode.pb.go
renamed
crypto/internal/pb/encode.proto
renamed
crypto/key.go
+6
-5
@@ -14,8 +14,9 @@ import (
14
"crypto/sha512"
15
"hash"
16
17
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
17
+ proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
18
19
+ pb "github.com/jbenet/go-ipfs/crypto/internal/pb"
20
u "github.com/jbenet/go-ipfs/util"
21
)
22
@@ -205,14 +206,14 @@ func KeyStretcher(cmp int, cipherType string, hashType string, secret []byte) ([
206
}
207
208
func UnmarshalPublicKey(data []byte) (PubKey, error) {
208
- pmes := new(PBPublicKey)
209
+ pmes := new(pb.PBPublicKey)
210
err := proto.Unmarshal(data, pmes)
211
if err != nil {
212
return nil, err
213
}
214
215
switch pmes.GetType() {
215
- case KeyType_RSA:
216
+ case pb.KeyType_RSA:
217
return UnmarshalRsaPublicKey(pmes.GetData())
218
default:
219
return nil, ErrBadKeyType
@@ -220,14 +221,14 @@ func UnmarshalPublicKey(data []byte) (PubKey, error) {
221
}
222
223
func UnmarshalPrivateKey(data []byte) (PrivKey, error) {
223
- pmes := new(PBPrivateKey)
224
+ pmes := new(pb.PBPrivateKey)
225
err := proto.Unmarshal(data, pmes)
226
if err != nil {
227
return nil, err
228
}
229
230
switch pmes.GetType() {
230
- case KeyType_RSA:
231
+ case pb.KeyType_RSA:
232
return UnmarshalRsaPrivateKey(pmes.GetData())
233
default:
234
return nil, ErrBadKeyType
crypto/rsa.go
+7
-5
@@ -8,7 +8,9 @@ import (
8
"crypto/x509"
9
"errors"
10
11
- "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
11
+ proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
12
+
13
+ pb "github.com/jbenet/go-ipfs/crypto/internal/pb"
14
)
15
16
type RsaPrivateKey struct {
@@ -34,8 +36,8 @@ func (pk *RsaPublicKey) Bytes() ([]byte, error) {
36
return nil, err
37
}
38
37
- pbmes := new(PBPublicKey)
38
- typ := KeyType_RSA
39
+ pbmes := new(pb.PBPublicKey)
40
+ typ := pb.KeyType_RSA
41
pbmes.Type = &typ
42
pbmes.Data = b
43
return proto.Marshal(pbmes)
@@ -67,8 +69,8 @@ func (sk *RsaPrivateKey) GetPublic() PubKey {
69
70
func (sk *RsaPrivateKey) Bytes() ([]byte, error) {
71
b := x509.MarshalPKCS1PrivateKey(sk.k)
70
- pbmes := new(PBPrivateKey)
71
- typ := KeyType_RSA
72
+ pbmes := new(pb.PBPrivateKey)
73
+ typ := pb.KeyType_RSA
74
pbmes.Type = &typ
75
pbmes.Data = b
76
return proto.Marshal(pbmes)