Files
filou/keys/encoding_test.go
2014-10-31 16:51:49 -07:00

56 lines
1.0 KiB
Go

package keys
import (
"encoding/json"
"reflect"
"testing"
. "github.com/didiercrunch/filou/helper"
)
func TestRSAPrivateKeyJsonification(t *testing.T) {
key := &RSAPrivateKey{B(1023), B(2112), B(328723), B(2332), 89}
data, err := json.Marshal(key)
if err != nil {
t.Error(err)
return
}
key2 := new(RSAPrivateKey)
if err := json.Unmarshal(data, key2); err != nil {
t.Error(err)
return
}
if !reflect.DeepEqual(key, key2) {
t.Fail()
}
}
func TestRSAPublicKeyJsonification(t *testing.T) {
key := &RSAPublicKey{B(1023), 89}
data, err := json.Marshal(key)
if err != nil {
t.Error(err)
return
}
key2 := new(RSAPublicKey)
if err := json.Unmarshal(data, key2); err != nil {
t.Error(err)
return
}
if !reflect.DeepEqual(key, key2) {
t.Fail()
}
}
func TestRSAPublicKeyJsonificationFromString(t *testing.T) {
data := []byte(`{"N":"3ff","E":89}`)
key := new(RSAPublicKey)
if err := json.Unmarshal(data, key); err != nil {
t.Error(err)
return
}
if !reflect.DeepEqual(key, &RSAPublicKey{B(1023), 89}) {
t.Fail()
}
}