コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RsaSmallCodeParser"/> class.
        /// </summary>
        /// <param name="codeLength">Length of the code.</param>
        /// <param name="rsaPublicKey">The RSA public key.</param>
        /// <param name="translator">The translator.</param>
        public RsaSmallCodeParser(int codeLength, RsaSmallPublicKey rsaPublicKey, IStringTranslator translator)
        {
            if (codeLength < 1)
            {
                throw new ArgumentOutOfRangeException("codeLength", "codeLenth must be greater than zero.");
            }

            if (rsaPublicKey == null)
            {
                throw new ArgumentNullException("rsaPublicKey");
            }
            if (translator == null)
            {
                throw new ArgumentNullException("translator");
            }

            char[] alphabetLetters = translator.FinalAlphabet.ToCharArray();

            Array.Sort(alphabetLetters);

            int i = 0;

            foreach (char alphabetLetter in alphabetLetters)
            {
                // Ignore duplicates
                if (alphabetLetter != correctDigitSequence[i])
                {
                    // Not a duplicate, move to next char in valid sequence of digits
                    i++;
                    if (alphabetLetter != correctDigitSequence[i])
                    {
                        throw new ArgumentException("The final alphabet does not contain a valid digit sequence.", "translator");
                    }
                }
            }
            radix = i + 1;

            rsa             = new RsaSmall(new RsaSmallFullKey(rsaPublicKey.Modulus, 0, rsaPublicKey.Exponent));
            this.translator = translator;
            validCodeRegex  =
                string.Format(CultureInfo.InvariantCulture, @"^[{0}]{{{1}}}$", translator.InitialAlphabet, codeLength);
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RsaSmallCodeParser"/> class.
        /// </summary>
        /// <param name="codeLength">Length of the code.</param>
        /// <param name="rsaPublicKey">The RSA public key.</param>
        /// <param name="translator">The translator.</param>
        public RsaSmallCodeParser(int codeLength, RsaSmallPublicKey rsaPublicKey, IStringTranslator translator)
        {
            if(codeLength < 1)
            {
                throw new ArgumentOutOfRangeException("codeLength", "codeLenth must be greater than zero.");
            }

            if (rsaPublicKey == null)
            {
                throw new ArgumentNullException("rsaPublicKey");
            }
            if (translator == null)
            {
                throw new ArgumentNullException("translator");
            }

            char[] alphabetLetters = translator.FinalAlphabet.ToCharArray();

            Array.Sort(alphabetLetters);

            int i = 0;
            foreach (char alphabetLetter in alphabetLetters)
            {
                // Ignore duplicates
                if (alphabetLetter != correctDigitSequence[i])
                {
                    // Not a duplicate, move to next char in valid sequence of digits
                    i++;
                    if (alphabetLetter != correctDigitSequence[i])
                    {
                        throw new ArgumentException("The final alphabet does not contain a valid digit sequence.", "translator");
                    }
                }
            }
            radix = i + 1;

            rsa = new RsaSmall(new RsaSmallFullKey(rsaPublicKey.Modulus, 0, rsaPublicKey.Exponent));
            this.translator = translator;
            validCodeRegex =
                string.Format(CultureInfo.InvariantCulture, @"^[{0}]{{{1}}}$", translator.InitialAlphabet, codeLength);
        }
コード例 #3
0
 public AddressValidator(IStringTranslator polishTranslator)
 {
     _polishTranslator = polishTranslator;
 }