github.com/ronperry/cryptoedge@v0.0.0-20150815114006-cc363e290743/jjm/types_test.go (about) 1 package jjm 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) //, PointRs1, PointRs2, ScalarLs1, ScalarLs2) 14 n.PointRs1, n.PointRs2 = *eccutil.ZeroPoint(), *eccutil.ZeroPoint() 15 n.ScalarLs1, n.ScalarLs2 = new(big.Int), new(big.Int) 16 17 b, err := n.Marshal() 18 if err != nil { 19 t.Fatalf("Marshalling failed: %s", err) 20 } 21 _, err = n.Unmarshal(b) 22 if err != nil { 23 t.Fatalf("UnMarshalling failed: %s", err) 24 } 25 n.PubKey.X = big.NewInt(3) 26 _, err = n.Unmarshal(b) 27 if err == nil { 28 t.Fatal("UnMarshalling must fail for foreign signer") 29 } 30 } 31 32 func Test_BlindingParamServer(t *testing.T) { 33 p := new(eccutil.Point) 34 p.X, p.Y = new(big.Int), new(big.Int) 35 n := NewBlindingParamServer(p) 36 n.ScalarKs1, n.ScalarKs2 = new(big.Int), new(big.Int) 37 n.PointRs1, n.PointRs2 = *eccutil.ZeroPoint(), *eccutil.ZeroPoint() 38 n.ScalarLs1, n.ScalarLs2 = new(big.Int), new(big.Int) 39 n.ScalarRs1, n.ScalarRs2 = new(big.Int), new(big.Int) 40 n.IsUsed = false 41 b, err := n.Marshal() 42 if err != nil { 43 t.Fatalf("Marshalling failed: %s", err) 44 } 45 _, err = n.Unmarshal(b) 46 if err != nil { 47 t.Fatalf("UnMarshalling failed: %s", err) 48 } 49 n.PubKey.X = big.NewInt(3) 50 _, err = n.Unmarshal(b) 51 if err == nil { 52 t.Fatal("UnMarshalling must fail for foreign signer") 53 } 54 } 55 56 func Test_ClearMessage(t *testing.T) { 57 n := NewClearMessage([]byte("Some message to test")) 58 b, err := n.Marshal() 59 if err != nil { 60 t.Fatalf("Marshalling failed: %s", err) 61 } 62 _, err = n.Unmarshal(b) 63 if err != nil { 64 t.Fatalf("UnMarshalling failed: %s", err) 65 } 66 if "bd328d95d29d43e1c1c11eaf6ad9502dc039fc9b5e7813cefa001b3dfd3bbcda" != hex.EncodeToString(n.UniqueID()) { 67 t.Error("Unique ID Wrong") 68 } 69 } 70 71 func Test_BlindingFactors(t *testing.T) { 72 p := new(eccutil.Point) 73 p.X, p.Y = new(big.Int), new(big.Int) 74 n := NewBlindingFactors(p) 75 76 n.ScalarW, n.ScalarZ, n.ScalarE, n.ScalarD, n.ScalarA = new(big.Int), new(big.Int), new(big.Int), new(big.Int), new(big.Int) 77 n.ScalarB, n.ScalarR1, n.ScalarR2, n.ScalarRs1, n.ScalarRs2 = new(big.Int), new(big.Int), new(big.Int), new(big.Int), new(big.Int) 78 n.PointR1, n.PointR2 = *eccutil.ZeroPoint(), *eccutil.ZeroPoint() 79 n.IsUsed = false 80 81 b, err := n.Marshal() 82 if err != nil { 83 t.Fatalf("Marshalling failed: %s", err) 84 } 85 _, err = n.Unmarshal(b) 86 if err != nil { 87 t.Fatalf("UnMarshalling failed: %s", err) 88 } 89 } 90 91 func Test_BlindMessage(t *testing.T) { 92 p := new(eccutil.Point) 93 p.X, p.Y = new(big.Int), new(big.Int) 94 n := NewBlindMessage(p) 95 n.M1, n.M2 = new(big.Int), new(big.Int) 96 b, err := n.Marshal() 97 if err != nil { 98 t.Fatalf("Marshalling failed: %s", err) 99 } 100 _, err = n.Unmarshal(b) 101 if err != nil { 102 t.Fatalf("UnMarshalling failed: %s", err) 103 } 104 n.PubKey.X = big.NewInt(3) 105 _, err = n.Unmarshal(b) 106 if err == nil { 107 t.Fatal("UnMarshalling must fail for foreign signer") 108 } 109 } 110 111 func Test_BlindSignature(t *testing.T) { 112 p := new(eccutil.Point) 113 p.X, p.Y = new(big.Int), new(big.Int) 114 n := NewBlindSignature(p) 115 116 n.ScalarS1, n.ScalarS2 = new(big.Int), new(big.Int) 117 b, err := n.Marshal() 118 if err != nil { 119 t.Fatalf("Marshalling failed: %s", err) 120 } 121 _, err = n.Unmarshal(b) 122 if err != nil { 123 t.Fatalf("UnMarshalling failed: %s", err) 124 } 125 n.PubKey.X = big.NewInt(3) 126 _, err = n.Unmarshal(b) 127 if err == nil { 128 t.Fatal("UnMarshalling must fail for foreign signer") 129 } 130 } 131 132 func Test_ClearSignature(t *testing.T) { 133 p := new(eccutil.Point) 134 p.X, p.Y = new(big.Int), new(big.Int) 135 n := NewClearSignature(p) 136 n.PointR = *eccutil.ZeroPoint() 137 n.ScalarS, n.ScalarR = new(big.Int), new(big.Int) 138 b, err := n.Marshal() 139 if err != nil { 140 t.Fatalf("Marshalling failed: %s", err) 141 } 142 _, err = n.Unmarshal(b) 143 if err != nil { 144 t.Fatalf("UnMarshalling failed: %s", err) 145 } 146 n.PubKey.X = big.NewInt(3) 147 _, err = n.Unmarshal(b) 148 if err == nil { 149 t.Fatal("UnMarshalling must fail for foreign signer") 150 } 151 }