Esempio n. 1
0
        public int CompareTo(AppVersion other)
        {
            AssertUtils.AssertNotNull(other);

            var compare = ComparableUtils.Compare(this.Major, other.Major);

            if (compare != 0)
            {
                return(compare);
            }

            compare = ComparableUtils.Compare(this.Minor, other.Minor);
            if (compare != 0)
            {
                return(compare);
            }

            compare = ComparableUtils.Compare(this.Build ?? 0, other.Build ?? 0);
            if (compare != 0)
            {
                return(compare);
            }

            return(ComparableUtils.Compare(this.Revision ?? 0, other.Revision ?? 0));
        }
Esempio n. 2
0
        public byte[] Digest(byte[] message)
        {
            Initialize();

            AssertUtils.AssertNotNull(message);
            return(macEngine.ComputeHash(message));
        }
        public string Digest(string message)
        {
            Initialize();
            AssertUtils.AssertNotNull(message);

            return(BaseEncoder.Encode(Digester.Digest(Charset.GetBytes(message))));
        }
        protected override void Init()
        {
            Charset     = ValueUtils.ValueOrDefault(Charset, Encoding.UTF8);
            BaseEncoder = ValueUtils.ValueOrDefault(BaseEncoder, BaseEncoder.Base64);

            AssertUtils.AssertNotNull(Digester);
        }
Esempio n. 5
0
        // Major - increased when the feature set/API of the software changes significantly
        // Minor - increased when notable changes are made, minor API changes or addition of new functionality
        // Build - increased when minor changes are made, typically bug fixes and improvements(though no API changes)
        // Revision - Represents the build instance

        public static AppVersion Parse(string version)
        {
            AssertUtils.AssertNotNull(version);
            if (!VersionPattern.IsMatch(version))
            {
                return(null);
            }
            string[] numbers = version.Split(new char[] { '.' });

            var appVersion = new AppVersion
            {
                Major = int.Parse(numbers[0]),
                Minor = int.Parse(numbers[1])
            };

            if (numbers.Length >= 3)
            {
                appVersion.Build = int.Parse(numbers[2]);
            }

            if (numbers.Length == 4)
            {
                appVersion.Revision = int.Parse(numbers[3]);
            }
            return(appVersion);
        }
Esempio n. 6
0
        public string Decrypt(string message)
        {
            Initialize();
            AssertUtils.AssertNotNull(message);

            return(Charset.GetString(Encryptor.Decrypt(BaseEncoder.Decode(message))));
        }
        public bool Verify(string message, string digested)
        {
            Initialize();
            AssertUtils.AssertNotNull(message);
            AssertUtils.AssertNotNull(digested);

            return(Digester.Verify(Charset.GetBytes(message), BaseEncoder.Decode(digested)));
        }
Esempio n. 8
0
        protected override void Init()
        {
            AssertUtils.AssertNotNull(Secret);
            AssertUtils.AssertNotNull(MacAlgm);

            this.macEngine = CreateMacEngine();

            Array.Clear(Secret, 0, Secret.Length);
        }
Esempio n. 9
0
        public bool Verify(byte[] message, byte[] digested)
        {
            Initialize();

            AssertUtils.AssertNotNull(message);
            AssertUtils.AssertNotNull(digested);

            byte[] hashed = macEngine.ComputeHash(message);
            return(hashed.SequenceEqual(digested));
        }
Esempio n. 10
0
        public new string Digest(string password)
        {
            Initialize();
            AssertUtils.AssertNotNull(password);

            byte[] salt = new byte[SaltSize];
            random.GetBytes(salt);

            byte[] secKey = secretKeyGenerator.Generate(password, salt, IterationCount, KeySize);
            return(BaseEncoder.Encode(ArrayUtils.Append(salt, secKey)));
        }
Esempio n. 11
0
        public EmailConfig(IConfiguration configuration)
        {
            var emailConfig = AssertUtils.AssertNotNull(configuration.GetSection("EmailConfig"));

            SmtpConfig = new SmtpConfig(emailConfig);

            FromEmail    = StringUtils.TrimToNull(emailConfig["FromEmail"]);
            FromName     = StringUtils.TrimToNull(emailConfig["FromName"]);
            NoReplyEmail = StringUtils.TrimToNull(emailConfig["NoReplyEmail"]);

            Init(emailConfig);
        }
        public async Task ExecuteResultAsync(ActionContext context)
        {
            var objectResult = new ObjectResult(
                new Result <string>()
            {
                IsError = true,
                Link    = AssertUtils.AssertNotNull(Link),
                Message = AssertUtils.AssertNotNull(Message)
            })
            {
                StatusCode = StatusCodes.Status409Conflict
            };

            await objectResult.ExecuteResultAsync(context);
        }
Esempio n. 13
0
        public SmtpConfig(IConfigurationSection emailConfig)
        {
            var config = AssertUtils.AssertNotNull(emailConfig.GetSection("SmtpConfig"));

            Host = AssertUtils.AssertNotNull(StringUtils.TrimToNull(config["SmtpHost"]));
            Port = Int32.Parse(AssertUtils.AssertNotNull(StringUtils.TrimToNull(config["SmtpPort"])));

            string enableSsl = StringUtils.TrimToNull(config["SmtpSsl"]);

            if (enableSsl != null)
            {
                EnableSsl = Boolean.Parse(enableSsl);
            }
            Login    = AssertUtils.AssertNotNull(StringUtils.TrimToNull(config["SmtpLogin"]));
            Password = StringUtils.TrimToDefault(config["SmtpPassword"], string.Empty);
        }
Esempio n. 14
0
        public new bool Verify(string password, string digested)
        {
            Initialize();
            AssertUtils.AssertNotNull(password);
            AssertUtils.AssertNotNull(digested);

            byte[] dg = BaseEncoder.Decode(digested);
            AssertUtils.AssertTrue(dg.Length > SaltSize);

            byte[] salt   = new byte[SaltSize];
            byte[] secKey = new byte[dg.Length - SaltSize];
            ArrayUtils.Copy(dg, salt, secKey);

            byte[] computedSecKey = secretKeyGenerator.Generate(password, salt, IterationCount, KeySize);
            return(computedSecKey.SequenceEqual(secKey));
        }
Esempio n. 15
0
        public object GetMutex(K key)
        {
            AssertUtils.AssertNotNull(key);

            object mutex = this.mutexMap[key];

            if (mutex == null)
            {
                lock (this.sharedMutex)
                {
                    if ((mutex = this.mutexMap[key]) == null)
                    {
                        mutex = new object();
                        this.mutexMap[key] = mutex;
                    }
                }
            }
            return(mutex);
        }
Esempio n. 16
0
        public static string GeRequiredValue(this ClaimsPrincipal user, string claimType)
        {
            Claim claim = AssertUtils.AssertNotNull(user.FindFirst(claimType));

            return(AssertUtils.AssertNotNull(claim.Value));
        }
Esempio n. 17
0
        public static int GetUserID(this ClaimsPrincipal user)
        {
            var claim = AssertUtils.AssertNotNull(user.FindFirst(UserID));

            return(System.Int32.Parse(claim.Value));
        }
Esempio n. 18
0
 protected override void Init()
 {
     AssertUtils.AssertNotNull(HashAlgm);
     this.hashEngine = CreateHashEngine(HashAlgm.Value);
 }
Esempio n. 19
0
 public static string GenerateToken(LoginToken loginToken, TextEncryptor signer)
 {
     AssertUtils.AssertNotNull(loginToken);
     return(signer.Encrypt(JsonConvert.SerializeObject(loginToken)));
 }
Esempio n. 20
0
 public static LoginToken ParseToken(string loginToken, TextEncryptor signer)
 {
     AssertUtils.AssertNotNull(loginToken);
     return(JsonConvert.DeserializeObject <LoginToken>(signer.Decrypt(loginToken)));
 }
Esempio n. 21
0
        public static string GetDisplayName(this ClaimsPrincipal user)
        {
            var claim = AssertUtils.AssertNotNull(user.FindFirst(DisplayName));

            return(claim.Value);
        }