github.com/ronperry/cryptoedge@v0.0.0-20150815114006-cc363e290743/jcc/types_test.go (about) 1 package jcc 2 3 import ( 4 "github.com/ronperry/cryptoedge/eccutil" 5 "encoding/hex" 6 "math/big" 7 "testing" 8 ) 9 10 func Test_BlindingParamClient(t *testing.T) { 11 p := new(eccutil.Point) 12 p.X, p.Y = new(big.Int), new(big.Int) 13 n := NewBlindingParamClient(p) 14 b, err := n.Marshal() 15 if err != nil { 16 t.Fatalf("Marshalling failed: %s", err) 17 } 18 _, err = n.Unmarshal(b) 19 if err != nil { 20 t.Fatalf("UnMarshalling failed: %s", err) 21 } 22 n.PubKey.X = big.NewInt(3) 23 _, err = n.Unmarshal(b) 24 if err == nil { 25 t.Fatal("UnMarshalling must fail for foreign signer") 26 } 27 } 28 29 func Test_ClearMessage(t *testing.T) { 30 n := NewClearMessage([]byte("Some message to test")) 31 b, err := n.Marshal() 32 if err != nil { 33 t.Fatalf("Marshalling failed: %s", err) 34 } 35 _, err = n.Unmarshal(b) 36 if err != nil { 37 t.Fatalf("UnMarshalling failed: %s", err) 38 } 39 if "bd328d95d29d43e1c1c11eaf6ad9502dc039fc9b5e7813cefa001b3dfd3bbcda" != hex.EncodeToString(n.UniqueID()) { 40 t.Error("Unique ID Wrong") 41 } 42 } 43 44 func Test_BlindingFactors(t *testing.T) { 45 p := new(eccutil.Point) 46 p.X, p.Y = new(big.Int), new(big.Int) 47 n := NewBlindingFactors(p) 48 b, err := n.Marshal() 49 if err != nil { 50 t.Fatalf("Marshalling failed: %s", err) 51 } 52 _, err = n.Unmarshal(b) 53 if err != nil { 54 t.Fatalf("UnMarshalling failed: %s", err) 55 } 56 n.PubKey.X = big.NewInt(3) 57 _, err = n.Unmarshal(b) 58 if err == nil { 59 t.Fatal("UnMarshalling must fail for foreign signer") 60 } 61 } 62 63 func Test_BlindMessage(t *testing.T) { 64 p := new(eccutil.Point) 65 p.X, p.Y = new(big.Int), new(big.Int) 66 n := NewBlindMessage(p) 67 n.Message.X, n.Message.Y = new(big.Int), new(big.Int) 68 b, err := n.Marshal() 69 if err != nil { 70 t.Fatalf("Marshalling failed: %s", err) 71 } 72 _, err = n.Unmarshal(b) 73 if err != nil { 74 t.Fatalf("UnMarshalling failed: %s", err) 75 } 76 n.PubKey.X = big.NewInt(3) 77 _, err = n.Unmarshal(b) 78 if err == nil { 79 t.Fatal("UnMarshalling must fail for foreign signer") 80 } 81 } 82 83 func Test_BlindSignature(t *testing.T) { 84 p := new(eccutil.Point) 85 p.X, p.Y = new(big.Int), new(big.Int) 86 n := NewBlindSignature(p) 87 n.R.X, n.R.Y = new(big.Int), new(big.Int) 88 n.S.X, n.S.Y = new(big.Int), new(big.Int) 89 b, err := n.Marshal() 90 if err != nil { 91 t.Fatalf("Marshalling failed: %s", err) 92 } 93 _, err = n.Unmarshal(b) 94 if err != nil { 95 t.Fatalf("UnMarshalling failed: %s", err) 96 } 97 n.PubKey.X = big.NewInt(3) 98 _, err = n.Unmarshal(b) 99 if err == nil { 100 t.Fatal("UnMarshalling must fail for foreign signer") 101 } 102 } 103 104 func Test_ClearSignature(t *testing.T) { 105 p := new(eccutil.Point) 106 p.X, p.Y = new(big.Int), new(big.Int) 107 n := NewClearSignature(p) 108 n.R.X, n.R.Y = new(big.Int), new(big.Int) 109 n.SB.X, n.SB.Y = new(big.Int), new(big.Int) 110 b, err := n.Marshal() 111 if err != nil { 112 t.Fatalf("Marshalling failed: %s", err) 113 } 114 _, err = n.Unmarshal(b) 115 if err != nil { 116 t.Fatalf("UnMarshalling failed: %s", err) 117 } 118 n.PubKey.X = big.NewInt(3) 119 _, err = n.Unmarshal(b) 120 if err == nil { 121 t.Fatal("UnMarshalling must fail for foreign signer") 122 } 123 } 124 125 func Test_BlindingParamServer(t *testing.T) { 126 p := new(eccutil.Point) 127 p.X, p.Y = new(big.Int), new(big.Int) 128 n := NewBlindingParamServer(p) 129 b, err := n.Marshal() 130 if err != nil { 131 t.Fatalf("Marshalling failed: %s", err) 132 } 133 _, err = n.Unmarshal(b) 134 if err != nil { 135 t.Fatalf("UnMarshalling failed: %s", err) 136 } 137 n.PubKey.X = big.NewInt(3) 138 _, err = n.Unmarshal(b) 139 if err == nil { 140 t.Fatal("UnMarshalling must fail for foreign signer") 141 } 142 }