Example #1
0
        public void ConvertBackAndForth()
        {
            var converter = new UnblindedSignatureJsonConverter();

            using var r   = new Key();
            using var key = new Key();
            var signer = new Signer(key);

            foreach (var i in Enumerable.Range(0, 100))
            {
                var requester = new Requester();

                var message = new byte[256];
                Random.NextBytes(message);
                var blindedMessage     = requester.BlindMessage(message, r.PubKey, key.PubKey);
                var blindSignature     = signer.Sign(blindedMessage, r);
                var unblindedSignature = requester.UnblindSignature(blindSignature);

                var sb = new StringBuilder();
                using var writer = new JsonTextWriter(new StringWriter(sb));
                converter.WriteJson(writer, unblindedSignature, null);

                using var reader = new JsonTextReader(new StringReader(sb.ToString()));
                var convertedUnblindedSignature = (UnblindedSignature)converter.ReadJson(reader, null, null, null);
                Assert.Equal(unblindedSignature.C, convertedUnblindedSignature.C);
                Assert.Equal(unblindedSignature.S, convertedUnblindedSignature.S);
            }
        }
Example #2
0
        public void DetectInvalidSerializedMessage()
        {
            var json = "[ '999999999999999999999999999999999999999999999999999999999999999999999999999999'," +             // 33 bytes (INVALID)
                       " '999999999999999999999999999']";

            using var reader = new JsonTextReader(new StringReader(json));
            var converter = new UnblindedSignatureJsonConverter();
            var ex        = Assert.Throws <FormatException>(() => converter.ReadJson(reader, null, null, null));

            Assert.Contains("longer than 32 bytes", ex.Message);
        }