public TokenProviderFactory(
     IRSAEncryptor rsaEncryptor,
     IRSAKeyParser rsaKeyParser,
     ISymmetricKeyGenerator keyGenerator,
     IAEADEncryptor aeadEncryptor)
 {
     this.rsaEncryptor  = rsaEncryptor.ThrowIfNull(nameof(rsaEncryptor));
     this.rsaKeyParser  = rsaKeyParser.ThrowIfNull(nameof(rsaKeyParser));
     this.keyGenerator  = keyGenerator.ThrowIfNull(nameof(keyGenerator));
     this.aeadEncryptor = aeadEncryptor.ThrowIfNull(nameof(aeadEncryptor));
 }
 public void ThrowsIfDependenciesAreNull(
     IRSAEncryptor rsaEncryptor,
     IRSAKeyParser rsaKeyParser,
     ISymmetricKeyGenerator keyGenerator,
     IAEADEncryptor aeadEncryptor,
     string paramName)
 {
     // Arrange/Act/Assert
     Assert.Throws <ArgumentNullException>(
         paramName,
         () => new TokenProviderFactory(rsaEncryptor, rsaKeyParser, keyGenerator, aeadEncryptor));
 }
Exemple #3
0
        public TokenProvider(
            IRSAEncryptor rsaEncryptor,
            IRSAKeyParser rsaKeyParser,
            ISymmetricKeyGenerator keyGenerator,
            IAEADEncryptor aeadEncryptor,
            TokenProviderSettings settings)
        {
            this.rsaEncryptor  = rsaEncryptor;
            this.rsaKeyParser  = rsaKeyParser;
            this.keyGenerator  = keyGenerator;
            this.aeadEncryptor = aeadEncryptor;

            this.settings = settings.ThrowIfNull(nameof(settings));

            if (!rsaKeyParser.TryParsePublic(settings.PublicKey, out publicKey))
            {
                throw new ArgumentException("Invalid RSA key", nameof(settings.PublicKey));
            }

            if (!rsaKeyParser.TryParsePrivate(settings.PrivateKey, out privateKey))
            {
                throw new ArgumentException("Invalid RSA key", nameof(settings.PrivateKey));
            }
        }