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