Ejemplo n.º 1
0
        public async Task <TEKSignature> CreateSignatureAsync(MemoryStream source, int batchNum, int batchSize)
        {
            var s = new TEKSignature();

            s.SignatureInfo = SigInfo;
            s.BatchNum      = batchNum;
            s.BatchSize     = batchSize;
            // Signature
            byte[] hash;
            using (var sha = System.Security.Cryptography.SHA256.Create())
            {
                hash = sha.ComputeHash(source);
            }
#if DEBUG
            using (var ecDsa = System.Security.Cryptography.ECDsaCng.Create(ECCurve.NamedCurves.nistP256))
            {
                s.Signature = ByteString.CopyFrom(ecDsa.SignHash(hash));
            }
#else
            var result = await KeyVault.SignAsync(TekExportKeyVaultKeyUrl, Microsoft.Azure.KeyVault.Cryptography.Algorithms.Es256.AlgorithmName, hash);

            s.Signature = ByteString.CopyFrom(result.Result);
#endif

            return(s);
        }
Ejemplo n.º 2
0
        public void PropertiesTest()
        {
            // preparation
            var model = new TEKSignature();

            // model property access
            Helper.ModelTestHelper.PropetiesTest(model);
        }
Ejemplo n.º 3
0
        public void EqualsMethodWithSameReference()
        {
            // preparation
            var instance = new TEKSignature();

            // action assert
            Assert.IsTrue(instance.Equals(instance));
        }
Ejemplo n.º 4
0
        public void EqualsMethodWithNull()
        {
            // preparation
            var instance = new TEKSignature();

            // action assert
            Assert.IsFalse(instance.Equals(null));
        }
Ejemplo n.º 5
0
        public void CreateMethod()
        {
            // preparation
            var instance = new TEKSignature();

            // assert
            Assert.IsNotNull(instance);
        }
 public TEKSignature CreateSignature(int batchNum, int batchSize)
 {
     var s = new TEKSignature();
     s.SignatureInfo = SigInfo;
     s.BatchNum = batchNum;
     s.BatchSize = batchSize;
     s.Signature = ByteString.CopyFrom(Signature);
     return s;
 }
        public async Task <TEKSignature> CreateSignatureAsync(MemoryStream source, int batchNum, int batchSize)
        {
            var s = new TEKSignature();

            s.BatchNum  = batchNum;
            s.BatchSize = batchSize;
            // Signature
            s.Signature = ByteString.CopyFrom(await SignService.SignAsync(source));
            return(s);
        }
Ejemplo n.º 8
0
        public void CalculateSizeMethod()
        {
            // preparation
            var instance = new TEKSignature();
            // action
            var actual = instance.CalculateSize();

            // assert
            Assert.AreEqual(0, actual);
        }
Ejemplo n.º 9
0
        public async Task <TEKSignature> CreateSignatureAsync(MemoryStream source, int batchNum, int batchSize)
        {
            Logger.LogInformation($"start {nameof(CreateSignatureAsync)}");
            var s = new TEKSignature();

            s.BatchNum  = batchNum;
            s.BatchSize = batchSize;
            // Signature
            s.Signature = ByteString.CopyFrom(await SignService.SignAsync(source));
            return(s);
        }
Ejemplo n.º 10
0
        public TEKSignature CreateSignature(Stream source, int batchNum, int batchSize)
        {
            var s = new TEKSignature();

            s.SignatureInfo = SigInfo;
            s.BatchNum      = batchNum;
            s.BatchSize     = batchSize;
            // TODO: Signature
            s.Signature = ByteString.CopyFrom(Signature);
            return(s);
        }
Ejemplo n.º 11
0
        public async Task <TEKSignature> CreateSignatureAsync(MemoryStream source, int batchNum, int batchSize)
        {
            var s = new TEKSignature();

            s.SignatureInfo = SigInfo;
            s.BatchNum      = batchNum;
            s.BatchSize     = batchSize;
            // Signature
            var hash = ECDsa.SignData(source, HashAlgorithmName.SHA256);

            s.Signature = ByteString.CopyFrom(ECDsa.SignHash(hash));
            return(s);
        }
Ejemplo n.º 12
0
        public void EqualsMethod()
        {
            // preparation
            var instance = new TEKSignature();
            // action
            var actual1 = instance.Clone();
            var actual2 = new TEKSignature(instance);

            // assert
            Assert.AreEqual(instance, actual1);
            Assert.AreEqual(instance, actual2);
            Assert.AreEqual(instance.GetHashCode(), actual1.GetHashCode());
            Assert.AreEqual(instance.GetHashCode(), actual2.GetHashCode());
        }
        public async Task <TEKSignature> CreateSignatureAsync(MemoryStream source, int batchNum, int batchSize)
        {
            var s = new TEKSignature();

            s.SignatureInfo = SigInfo;
            s.BatchNum      = batchNum;
            s.BatchSize     = batchSize;
            // Signature
            var ecdsap256 = System.Security.Cryptography.ECDsaCng.Create(ECCurve.NamedCurves.nistP256);
            var hash      = ecdsap256.SignData(source, HashAlgorithmName.SHA256);

#if DEBUG
            s.Signature = ByteString.CopyFrom(ecdsap256.SignHash(hash));
#else
            var result = await KeyVault.SignAsync(TekExportKeyVaultKeyUrl, Microsoft.Azure.KeyVault.Cryptography.Algorithms.Es256.AlgorithmName, hash);

            s.Signature = ByteString.CopyFrom(result.Result);
#endif
            return(s);
        }
Ejemplo n.º 14
0
        public void EqualsMethodWithSetValue()
        {
            // preparation
            var instance = new TEKSignature();

            instance.BatchNum      = 99;
            instance.BatchSize     = 99;
            instance.Signature     = ByteString.CopyFromUtf8("Signature");
            instance.SignatureInfo = new SignatureInfo();
            // action
            var actual1 = instance.Clone();
            var actual2 = new TEKSignature(instance);
            var actual3 = new TEKSignature();
            var actual4 = new TEKSignature();

            using var memory   = new MemoryStream();
            using var codedOut = new CodedOutputStream(memory, true);
            instance.WriteTo(codedOut);
            codedOut.Flush();
            memory.Position   = 0;
            using var codedIn = new CodedInputStream(memory, true);
            actual3.MergeFrom(codedIn);
            actual4.MergeFrom(actual3);
            // assert
            Assert.AreEqual(instance, actual1);
            Assert.AreEqual(instance, actual2);
            Assert.AreEqual(instance, actual3);
            Assert.AreEqual(instance, actual4);
            Assert.AreEqual(instance.GetHashCode(), actual1.GetHashCode());
            Assert.AreEqual(instance.GetHashCode(), actual2.GetHashCode());
            Assert.AreEqual(instance.GetHashCode(), actual3.GetHashCode());
            Assert.AreEqual(instance.GetHashCode(), actual4.GetHashCode());
            Assert.AreEqual(instance.CalculateSize(), actual1.CalculateSize());
            Assert.AreEqual(instance.CalculateSize(), actual2.CalculateSize());
            Assert.AreEqual(instance.CalculateSize(), actual3.CalculateSize());
            Assert.AreEqual(instance.CalculateSize(), actual4.CalculateSize());
            Assert.AreEqual(instance.ToString(), actual1.ToString());
            Assert.AreEqual(instance.ToString(), actual2.ToString());
            Assert.AreEqual(instance.ToString(), actual3.ToString());
            Assert.AreEqual(instance.ToString(), actual4.ToString());
        }
Ejemplo n.º 15
0
        public void EqualsMethodWithClear()
        {
            // preparation
            var instance = new TEKSignature();

            instance.BatchNum      = 99;
            instance.BatchSize     = 99;
            instance.Signature     = ByteString.CopyFromUtf8("Signature");
            instance.SignatureInfo = new SignatureInfo();
            var actual = instance.Clone();

            // action assert
            actual.ClearBatchNum();
            Assert.AreNotEqual(instance, actual);
            actual = instance.Clone();
            actual.ClearBatchSize();
            Assert.AreNotEqual(instance, actual);
            actual = instance.Clone();
            actual.ClearSignature();
            Assert.AreNotEqual(instance, actual);
        }
Ejemplo n.º 16
0
 public void CreateMethod()
 {
     // preparation
     var instance = new TEKSignature();
 }