Пример #1
0
        public static int Main(string[] args)
        {
            return(Parser.Default.ParseArguments <EncryptOptions, DecryptOptions>(args)
                   .MapResult(
                       (EncryptOptions options) =>
            {
                var timestamp = options.Timestamp ?? BrancaToken.GetBrancaTimestamp(DateTimeOffset.UtcNow);

                var result = new BrancaService().Encrypt(options.Key, options.KeyType, timestamp, options.Payload);
                if (result.IsSuccess)
                {
                    Console.WriteLine(result.Value);
                    return 0;
                }

                Console.WriteLine(result.Error);
                return 1;
            },
                       (DecryptOptions options) =>
            {
                var result = new BrancaService().Decrypt(options.Key, options.KeyType, options.Token);
                if (result.IsSuccess)
                {
                    Console.WriteLine($"Payload: {result.Value.Payload}");
                    Console.WriteLine($"Timestamp: {result.Value.BrancaFormatTimestamp} ({result.Value.Timestamp})");
                    return 0;
                }

                Console.WriteLine(result.Error);
                return 1;
            },
                       errors => 1));
        }
 public void GetBrancaTimestamp_WhenAfterMaxTimestamp_ExpectInvalidOperationException()
 {
     Assert.Throws <InvalidOperationException>(()
                                               => BrancaToken.GetBrancaTimestamp(new DateTime(2106, 02, 07, 06, 28, 16, DateTimeKind.Utc)));
 }
        public void GetBrancaTimestamp_WhenMaxTimestamp_ExpectUintMax()
        {
            var timestamp = BrancaToken.GetBrancaTimestamp(new DateTime(2106, 02, 07, 06, 28, 15, DateTimeKind.Utc));

            timestamp.Should().Be(uint.MaxValue);
        }
        public void GetBrancaTimestamp_When27November_ExpectZero()
        {
            var timestamp = BrancaToken.GetBrancaTimestamp(new DateTime(1973, 11, 27, 0, 0, 0, DateTimeKind.Utc));

            timestamp.Should().Be(123206400);
        }
        public void GetBrancaTimestamp_WhenUnixTimeStart_ExpectZero()
        {
            var timestamp = BrancaToken.GetBrancaTimestamp(new DateTime(1970, 01, 01, 0, 0, 0, DateTimeKind.Utc));

            timestamp.Should().Be(uint.MinValue);
        }
 public void GetBrancaTimestamp_WhenDateBeforeUnixTimeStart_ExpectException()
 {
     Assert.Throws <InvalidOperationException>(()
                                               => BrancaToken.GetBrancaTimestamp(new DateTime(1969, 01, 01)));
 }