예제 #1
0
        public void Init()
        {
            _view.Render();

            while (true)
            {
                var message = KeyReader.Read(Console.ReadKey(true));

                if (message.Body == "quit")
                {
                    break;
                }
                if (message.Header == "error")
                {
                    continue;
                }

                _model.InputBuffer.Send(message);

                if (_model.CurrentTurnMessages != null)
                {
                    _model.CurrentTurnMessages.ToList().ForEach(msg =>
                                                                Console.WriteLine(String.Format("The {0} {1} from {2}, to {3}", msg.Name, msg.Type, msg.From, msg.To)));
                }
            }
        }
예제 #2
0
        public void ReadPublicKeyFromPKCS12()
        {
            RSA rsa = KeyReader.ReadPublicKey(PFX_PATH, PFX_PASSWORD);

            Assert.IsNotNull(rsa);
            rsa.Dispose();
        }
예제 #3
0
        private bool HasJoinKeyOverride(NewReader reader, KeyReader joinKey)
        {
            IReference         childReference = joinKey.Reference.Find(ReferenceFlags.Child);
            IReferenceMetadata targetMetadata = childReference.List ?? childReference.Metadata;

            return(reader.Properties.Any(r => r.Metadata.Identity.Equals(targetMetadata.Identity)));
        }
예제 #4
0
        public void ReadKey(string keyId, Domain domain, string keyName, Type dataType, object defaultVal, string inputStr)
        {
            //<key id="nd0" for="node" attr.name="X1" attr.type="string" />

            var keyReader = new KeyReader();
            var reader = new XmlTextReader(new StringReader(inputStr));
            reader.Read();
            Assert.True(reader.IsStartElement());
            Assert.True(string.Compare("key", reader.Name, true) == 0, string.Format("Reader.Name should match expected, not: \"{0}\"", reader.Name));

            string retrievedKeyId;
            Domain retrievedDomain;
            string retrievedAttribName;
            Type retrievedType;
            object retrievedDefault;
            keyReader.Read(out retrievedKeyId, out retrievedDomain, out retrievedAttribName, out retrievedType, out retrievedDefault, reader);

            Assert.Equal(keyId, retrievedKeyId);
            Assert.Equal(domain, retrievedDomain);
            Assert.Equal(keyName, retrievedAttribName);
            Assert.Equal(dataType, retrievedType);
            Assert.Equal(defaultVal, retrievedDefault);

            if (!reader.IsEmptyElement)
                Assert.True(string.Compare("key", reader.Name, true) == 0, string.Format("End Reader.Name should match expected, not: \"{0}\"", reader.Name));
        }
예제 #5
0
        private void InitializeKey(KeyReader key)
        {
            if (key.Reference != null)
            {
                foreach (DataReader value in key.Values)
                {
                    value.KeyType = value.Metadata.Type.GetKeyType();
                }

                key.KeyType = CompositeKey.Create(key.Values.Select(v => v.KeyType));

                if (key.Values.Count > 1)
                {
                    key.Variable = Expression.Variable(key.KeyType);
                }

                if (key.Reference.HasFlag(ReferenceFlags.Self))
                {
                    key.Reference = this.GetRecursiveReference(key.Reference);
                }
            }

            foreach (DataReader value in key.Values)
            {
                value.IsDbNull ??= this.GetNamedVariable(typeof(bool), value, "_isnull");
                value.Variable ??= this.GetNamedVariable(value.KeyType, value);
            }
        }
예제 #6
0
        public void ReadPublicKeyFromPem()
        {
            RSA rsa = KeyReader.ReadPublicKey(PEM_PATH, null);

            Assert.IsNotNull(rsa);
            rsa.Dispose();
        }
예제 #7
0
        public byte[] EncriptData()
        {
            RSA pkeyid = KeyReader.ReadPrivateKeyFromPKCS12(PFX_PATH, PFX_PASSWORD);

            byte[] data = pkeyid.Encrypt(Encoding.Default.GetBytes(DATA), RSAEncryptionPadding.Pkcs1);
            pkeyid.Dispose();

            Assert.IsNotNull(data);
            return(data);
        }
예제 #8
0
        public byte[] SignData()
        {
            RSA pkeyid = KeyReader.ReadPrivateKeyFromPKCS12(PFX_PATH, PFX_PASSWORD);

            byte[] signature = pkeyid.SignData(Encoding.Default.GetBytes(DATA), HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1);
            pkeyid.Dispose();

            Assert.IsNotNull(signature);
            return(signature);
        }
예제 #9
0
        public void VerifyData()
        {
            RSA cert = KeyReader.ReadPublicKey(PEM_PATH, null);

            byte[] signature = SignData();

            Assert.IsTrue(cert.VerifyData(Encoding.Default.GetBytes(DATA), signature, HashAlgorithmName.SHA1, RSASignaturePadding.Pkcs1));

            cert.Dispose();
        }
예제 #10
0
        public void DecriptData()
        {
            RSA pkeyid = KeyReader.ReadPrivateKeyFromPKCS12(PFX_PATH, PFX_PASSWORD);

            byte[] data = EncriptData();

            byte[] decripted = pkeyid.Decrypt(data, RSAEncryptionPadding.Pkcs1);
            pkeyid.Dispose();

            Assert.AreEqual(DATA, Encoding.Default.GetString(decripted));
        }
예제 #11
0
        public void ConvertDefaultValStr(string defaultValStr, object expectedResult, Type valType)
        {
            var keyReader = new KeyReader();
            var result = keyReader.ConvertDefaultValStr(defaultValStr, valType);

            if (defaultValStr!=null)
            {
                Assert.NotNull(result);
                Assert.Equal(valType, result.GetType());
                Assert.Equal(expectedResult, result);
            }
        }
예제 #12
0
        private static GoogleOAuth2AuthenticationOptions GetGoogleOptions()
        {
            var reader  = new KeyReader();
            var keys    = reader.GetKey("google");
            var options = new GoogleOAuth2AuthenticationOptions()
            {
                ClientId     = keys.Public,
                ClientSecret = keys.Private
            };

            return(options);
        }
예제 #13
0
        private static FacebookAuthenticationOptions GetFacebookOptions()
        {
            var reader  = new KeyReader();
            var keys    = reader.GetKey("facebook");
            var options = new FacebookAuthenticationOptions()
            {
                AppId     = keys.Public,
                AppSecret = keys.Private
            };

            options.Scope.Add("email");
            return(options);
        }
예제 #14
0
        static void Main(string[] args)
        {
            var consoleArgs = new ConsoleArguments(args);

            if (consoleArgs.ContainsSwitch("-h") || consoleArgs.ContainsSwitch("-?") || args.Length <= 0)
            {
                PrintHelp();
                return;
            }
            var p = new Dictionary <string, string>();

            p["key"]     = consoleArgs.GetSwitchValue("-k");
            p["account"] = consoleArgs.GetSwitchValue("-a");
            p["share"]   = consoleArgs.GetSwitchValue("-s");
            p["dir"]     = consoleArgs.GetSwitchValue("-d");
            if (p.Values.Any(string.IsNullOrWhiteSpace))
            {
                PrintHelp();
                return;
            }
            var logger = new ConsoleLogger();
            var keys   = new KeyReader(p["key"]);
            var dir    = new DirectoryInfo(p["dir"]);

            if (!dir.Exists)
            {
                throw new ArgumentException(string.Format("Invalid directory {0}", p["dir"]));
            }
            var sw      = Stopwatch.StartNew();
            var dirSync = new DirectorySync(keys.GetByAccountName(p["account"]), p["share"], dir, logger)
            {
                RunAsync = consoleArgs.ContainsSwitch("-async")
            };

            if (consoleArgs.ContainsSwitch("-deleteAll"))
            {
                dirSync.DeleteAll();
            }
            else if (consoleArgs.ContainsSwitch("-force"))
            {
                dirSync.CleanAndDownload();
            }
            else
            {
                dirSync.Sync();
            }
            sw.Stop();
            logger.WriteLine("");
            logger.WriteLine("FINISH THE SYNC IN {0}", sw.Elapsed);
        }
예제 #15
0
        private static void ReadEncryptedPkcs8 <TRet>(
            string[] validOids,
            ReadOnlyMemory <byte> source,
            ReadOnlySpan <char> password,
            ReadOnlySpan <byte> passwordBytes,
            KeyReader <TRet> keyReader,
            out int bytesRead,
            out TRet ret)
        {
            int read;
            EncryptedPrivateKeyInfoAsn epki;

            try
            {
                AsnValueReader reader = new AsnValueReader(source.Span, AsnEncodingRules.BER);
                read = reader.PeekEncodedValue().Length;
                EncryptedPrivateKeyInfoAsn.Decode(ref reader, source, out epki);
            }
            catch (AsnContentException e)
            {
                throw new CryptographicException(SR.Cryptography_Der_Invalid_Encoding, e);
            }

            // No supported encryption algorithms produce more bytes of decryption output than there
            // were of decryption input.
            byte[]        decrypted       = CryptoPool.Rent(epki.EncryptedData.Length);
            Memory <byte> decryptedMemory = decrypted;

            try
            {
                int decryptedBytes = PasswordBasedEncryption.Decrypt(
                    epki.EncryptionAlgorithm,
                    password,
                    passwordBytes,
                    epki.EncryptedData.Span,
                    decrypted);

                decryptedMemory = decryptedMemory.Slice(0, decryptedBytes);

                ReadPkcs8(
                    validOids,
                    decryptedMemory,
                    keyReader,
                    out int innerRead,
                    out ret);

                if (innerRead != decryptedMemory.Length)
                {
                    ret = default !;
예제 #16
0
        public void ReadDefault(string expectedVal, string inputStr)
        {
            var keyReader = new KeyReader();
            var reader = new XmlTextReader(new StringReader(inputStr));
            reader.Read();
            Assert.True(reader.IsStartElement());
            Assert.True(string.Compare("default", reader.Name, true) == 0, string.Format( "Reader.Name should match expected, not: \"{0}\"", reader.Name));

            string defalutValStr;
            keyReader.ReadDefault(out defalutValStr, reader);
            Assert.Equal(expectedVal, defalutValStr);

            if (!reader.IsEmptyElement)
                Assert.True(string.Compare("default", reader.Name, true) == 0, string.Format("End Reader.Name should match expected, not: \"{0}\"", reader.Name));
        }
예제 #17
0
 internal static unsafe void ReadEncryptedPkcs8 <TRet>(
     string[] validOids,
     ReadOnlySpan <byte> source,
     ReadOnlySpan <char> password,
     KeyReader <TRet> keyReader,
     out int bytesRead,
     out TRet ret)
 {
     fixed(byte *ptr = &MemoryMarshal.GetReference(source))
     {
         using (MemoryManager <byte> manager = new PointerMemoryManager <byte>(ptr, source.Length))
         {
             ReadEncryptedPkcs8(validOids, manager.Memory, password, keyReader, out bytesRead, out ret);
         }
     }
 }
예제 #18
0
 private static void ReadEncryptedPkcs8 <TRet>(
     string[] validOids,
     ReadOnlyMemory <byte> source,
     ReadOnlySpan <byte> passwordBytes,
     KeyReader <TRet> keyReader,
     out int bytesRead,
     out TRet ret)
 {
     ReadEncryptedPkcs8(
         validOids,
         source,
         ReadOnlySpan <char> .Empty,
         passwordBytes,
         keyReader,
         out bytesRead,
         out ret);
 }
예제 #19
0
        private ParameterExpression GetListVariable(IBindingMetadata metadata, KeyReader joinKey)
        {
            if (joinKey != null)
            {
                Type dictType = typeof(Dictionary <,>).MakeGenericType(joinKey.KeyType, typeof(ElasticArray));

                return(this.GetNamedVariable(dictType, metadata.Identity));
            }
            else if (metadata.HasFlag(BindingMetadataFlags.Item))
            {
                Type listType = metadata.Parent.Composition?.Construct?.Type ?? throw BindingException.InvalidConstructor(metadata.Parent);

                return(this.GetNamedVariable(listType, metadata.Identity));
            }

            return(null);
        }
예제 #20
0
        private void AddChildKey(ListResult result, TargetWriter writer)
        {
            IList <IReference> references = this.GetChildReferences(writer.Source.Metadata).ToList();
            KeyReader          childKey   = references.Select(r => this.FindChildKey(writer.Source, r)).NotNull().FirstOrDefault();

            if (childKey != null && this.IsValidJoinKey(childKey, throwOnInvalid: true))
            {
                this.InitializeKey(childKey);
            }

            if (childKey == null && this.RequiresReference(writer.Source.Metadata))
            {
                throw BindingException.NoReferenceFound(writer.Source.Metadata);
            }

            writer.List = this.GetListTarget(result, writer.Source.Metadata, childKey);
            writer.Join = this.GetJoinTarget(result, childKey);
        }
예제 #21
0
        private bool IsValidJoinKey(KeyReader joinKey, bool throwOnInvalid = false)
        {
            IReferenceKey parentKey = joinKey.Reference.FindParentKey();
            IReferenceKey childKey  = joinKey.Reference.FindChildKey();

            foreach (var(childValue, parentValue) in childKey.Properties.Zip(parentKey.Properties))
            {
                Type parentType = parentValue.Type.GetKeyType();
                Type childType  = childValue.Type.GetKeyType();

                if (parentType != childType && throwOnInvalid)
                {
                    throw BindingException.InvalidReference(joinKey.Reference);
                }
                else if (parentType != childType)
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #22
0
        private JoinTarget GetJoinTarget(ListResult result, KeyReader joinKey)
        {
            if (joinKey == null)
            {
                return(null);
            }

            ListTarget list   = this.GetListTarget(result, joinKey.Target, joinKey);
            JoinTarget target = new JoinTarget()
            {
                Key    = joinKey,
                Buffer = Expression.Variable(typeof(ElasticArray), "_joinbuf"),
                Index  = this.Buffer.GetJoinIndex(joinKey.Reference),
                List   = list,
            };

            if (joinKey.Target.HasFlag(BindingMetadataFlags.Item))
            {
                target.NewList   = joinKey.Target.Parent.Composition.Construct;
                target.AddMethod = joinKey.Target.Parent.Composition.Add;
            }

            return(target);
        }
예제 #23
0
        public static Node GetSyntaxProcessorLinkedList()
        {
            IDataReader keyReader   = new KeyReader();
            IDataReader valueReader = new ValueReader();

            Node root = new Node(new OneWordSyntaxValidator(Constants.Draw), keyReader);
            Node temp = root.NextNode = new Node(new WordListSyntaxValidator(new HashSet <string> {
                "a", "an"
            }), null);

            temp = temp.NextNode = new Node(new ShapeNameSyntaxValidator(), valueReader);
            temp = temp.NextNode = new Node(new OneWordSyntaxValidator("with"), null);
            var loopNode = temp = temp.NextNode = new Node(new WordListSyntaxValidator(new HashSet <string> {
                "a", "an"
            }), null);

            temp          = temp.NextNode = new Node(new MeasurementNameSyntaxValidator(), keyReader);
            temp          = temp.NextNode = new Node(new OneWordSyntaxValidator("of"), null);
            temp          = temp.NextNode = new Node(new IntegerSyntaxValidator(), valueReader);
            temp          = temp.NextNode = new Node(new OneWordSyntaxValidator("and"), null);
            temp.NextNode = loopNode;

            return(root);
        }
예제 #24
0
        private ListTarget GetListTarget(ListResult result, IBindingMetadata metadata, KeyReader joinKey)
        {
            int bufferIndex = this.Buffer.GetListIndex(metadata, joinKey?.Reference);

            metadata = joinKey?.Target ?? metadata;

            ListTarget target = result.Targets.FirstOrDefault(t => t.Index == bufferIndex);

            if (target != null)
            {
                return(target);
            }

            target = new ListTarget()
            {
                Index    = bufferIndex,
                Variable = this.GetListVariable(metadata, joinKey),
            };

            if (joinKey == null && metadata.HasFlag(BindingMetadataFlags.Item))
            {
                target.NewList   = target.NewTarget = metadata.Parent.Composition?.Construct ?? throw BindingException.InvalidConstructor(metadata.Parent);
                target.AddMethod = metadata.Parent.Composition.Add;
            }

            if (joinKey != null)
            {
                target.NewTarget = Expression.New(target.Variable.Type);
            }

            if (target.NewTarget != null)
            {
                result.Targets.Add(target);
            }

            return(target);
        }
예제 #25
0
        public void ReadKey_And_Veryfy_Type(Type expectedKeyType, string keyId, Domain domain, string keyName, Type dataType, object defaultVal, string inputStr)
        {
            var keyReader = new KeyReader();
            var reader = new XmlTextReader(new StringReader(inputStr));
            reader.Read();
            Assert.True(reader.IsStartElement());
            Assert.True(string.Compare("key", reader.Name, true) == 0, string.Format("Reader.Name should match expected, not: \"{0}\"", reader.Name));

            Key key = null;
            keyReader.Read(out key, reader);

            Assert.NotNull(key);
            Assert.Equal(expectedKeyType, key.GetType());
            Assert.Equal(keyId, key.Id);
            Assert.Equal(domain, key.Domain);
            Assert.Equal(keyName, key.Name);
            Assert.Equal(dataType, key.DataType);
            if (defaultVal!=null)
                Assert.Equal(defaultVal.ToString(), key.DefaultString);

            if (!reader.IsEmptyElement)
                Assert.True(string.Compare("key", reader.Name, true) == 0, string.Format("End Reader.Name should match expected, not: \"{0}\"", reader.Name));
        }
예제 #26
0
        public static async Task <string> Run(SignOptions options)
        {
            var serviceProvider = new ServiceCollection()
                                  .AddHttpMessageSigning()
                                  .BuildServiceProvider();
            var requestSignerFactory = serviceProvider.GetRequiredService <IRequestSignerFactory>();

            ISignatureAlgorithm signatureAlgorithm;

            if (string.IsNullOrEmpty(options.KeyType) || options.KeyType.Equals("RSA", StringComparison.OrdinalIgnoreCase))
            {
                signatureAlgorithm = RSASignatureAlgorithm.CreateForSigning(HashAlgorithmName.SHA512, KeyReader.ReadRSA(options.PrivateKey));
            }
            else if (options.KeyType.Equals("P256", StringComparison.OrdinalIgnoreCase) || options.KeyType.Equals("ECDSA", StringComparison.OrdinalIgnoreCase))
            {
                signatureAlgorithm = ECDsaSignatureAlgorithm.CreateForSigning(HashAlgorithmName.SHA512, KeyReader.ReadECDsaPrivate(options.PrivateKey));
            }
            else if (options.KeyType.Equals("HMAC", StringComparison.OrdinalIgnoreCase))
            {
                signatureAlgorithm = SignatureAlgorithm.CreateForSigning(options.PrivateKey, HashAlgorithmName.SHA512);
            }
            else
            {
                throw new NotSupportedException("The specified key type is not supported.");
            }

            if (!string.IsNullOrEmpty(options.Algorithm) &&
                !options.Algorithm.StartsWith("rsa", StringComparison.OrdinalIgnoreCase) &&
                !options.Algorithm.StartsWith("hmac", StringComparison.OrdinalIgnoreCase) &&
                !options.Algorithm.StartsWith("ecdsa", StringComparison.OrdinalIgnoreCase))
            {
                signatureAlgorithm = new CustomSignatureAlgorithm(options.Algorithm);
            }

            var signingSettings = new SigningSettings {
                SignatureAlgorithm  = signatureAlgorithm,
                EnableNonce         = false,
                DigestHashAlgorithm = HashAlgorithmName.SHA256,
                AutomaticallyAddRecommendedHeaders = false,
                Headers = options.Headers
                          ?.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                          .Select(h => new HeaderName(h))
                          .ToArray()
            };
            var signer = requestSignerFactory.Create(
                new KeyId("test"),
                signingSettings);

            var created = DateTimeOffset.UtcNow;

            if (!string.IsNullOrEmpty(options.Created))
            {
                var createdUnix = int.Parse(options.Created);
                created = DateTimeOffset.FromUnixTimeSeconds(createdUnix);
            }

            var expires = signingSettings.Expires;

            if (!string.IsNullOrEmpty(options.Expires))
            {
                var expiresUnix     = int.Parse(options.Expires);
                var expiresAbsolute = DateTimeOffset.FromUnixTimeSeconds(expiresUnix);
                expires = expiresAbsolute - created;
            }

            await signer.Sign(options.Message, created, expires);

            var serializedMessage = HttpMessageSerializer.Serialize(options.Message);

            return(serializedMessage);
        }
예제 #27
0
        static void Main(string[] args)
        {
            IQueue queue = new AzurePrintsQueue();
            IStorage storage = new AzurePrintsStorage();
            IKeyReader reader = new KeyReader();

            Execute(queue, storage, reader);
        }
예제 #28
0
 public UserController()
 {
     _userService = new UserService(new UserRepository(new AesEncryptor(KeyReader.Instance().GetKey())), new AuthenticatorFactory(), new UserMapper(new AesEncryptor(KeyReader.Instance().GetKey())));
 }
예제 #29
0
        void ParseAnimator(Node node)
        {
            IAnimator animator = null;
            string    type     = lexer.ParseQuotedString();

            frames.Clear();
            functions.Clear();
            values.Clear();
            lexer.ParseToken('{');
            string propertyName = "";
            string className    = "";

            while (lexer.PeekChar() != '}')
            {
                var name = lexer.ParseWord();
                switch (name)
                {
                case "Property":
                    string[] s = lexer.ParseQuotedString().Split('@');
                    propertyName = s[0];
                    className    = s[1];
                    switch (propertyName)
                    {
                    case "AlongTrackOrientation":
                        propertyName = "AlongPathOrientation";
                        break;

                    case "File":
                        propertyName = "Sample";
                        break;

                    case "TexCoordForMins":
                        propertyName = "UV0";
                        break;

                    case "TexCoordForMaxs":
                        propertyName = "UV1";
                        break;

                    case "WidgetName":
                        propertyName = "WidgetId";
                        break;

                    case "TexturePath":
                        propertyName = "Texture";
                        break;

                    case "Anchor":
                        propertyName = "Position";
                        break;

                    case "BlendMode":
                        propertyName = "Blending";
                        break;

                    case "AnimationFPS":
                        propertyName = "AnimationFps";
                        break;

                    case "Life":
                        propertyName = "Lifetime";
                        break;

                    case "FontSize":
                        propertyName = "FontHeight";
                        break;

                    case "HAlign":
                        propertyName = "HAlignment";
                        break;

                    case "VAlign":
                        propertyName = "VAlignment";
                        break;

                    case "SplineName":
                        propertyName = "SplineId";
                        break;

                    case "RandMotionRadius":
                        propertyName = "RandomMotionRadius";
                        break;

                    case "RandMotionRotation":
                        propertyName = "RandomMotionRotation";
                        break;

                    case "RandMotionSpeed":
                        propertyName = "RandomMotionSpeed";
                        break;

                    case "RandMotionAspectRatio":
                        propertyName = "RandomMotionAspectRatio";
                        break;

                    case "TextColor":
                        propertyName = "TextColor";
                        break;
                    }
                    switch (propertyName + '@' + className)
                    {
                    case "ShadowColor@Hot::Text":
                    case "TextColor@Hot::TextPresenter":
                    case "ShadowColor@Hot::TextPresenter":
                        animator = new Color4Animator();
                        break;

                    case "Blending@Hot::MaskedEffect":
                        animator = new Animator <Blending>();
                        break;

                    case "AlongTrackOrientation@Hot::ParticleEmitter":
                        animator = new Animator <bool>();
                        break;

                    case "WidgetId@Hot::Gear":
                        animator = new Animator <NodeReference <Widget> >();
                        break;

                    case "SplineId@Hot::Gear":
                        animator = new Animator <NodeReference <Spline> >();
                        break;

                    case "AspectRatio@Hot::ParticleTemplate":
                    case "Scale@Hot::ParticleTemplate":
                        animator = new NumericAnimator();
                        break;

                    default:
                        animator = node.Animators[propertyName];
                        break;
                    }
                    break;

                case "Frames":
                    lexer.ParseToken('[');
                    while (lexer.PeekChar() != ']')
                    {
                        if (!isTangerine)
                        {
                            frames.Add(lexer.ParseInt() * 2);
                        }
                        else
                        {
                            frames.Add(lexer.ParseInt());
                        }
                    }
                    lexer.ParseToken(']');
                    break;

                case "Attributes":
                    lexer.ParseToken('[');
                    while (lexer.PeekChar() != ']')
                    {
                        functions.Add((KeyFunction)lexer.ParseInt());
                    }
                    lexer.ParseToken(']');
                    break;

                case "Keys":
                    KeyReader keyReader = GetKeyReader(type, propertyName, className);
                    lexer.ParseToken('[');
                    while (lexer.PeekChar() != ']')
                    {
                        values.Add(keyReader());
                    }
                    lexer.ParseToken(']');
                    break;

                default:
                    throw new Lime.Exception("Unknown property '{0}'. Parsing: {1}", name, animator);
                }
            }
            lexer.ParseToken('}');
            if (values.Count > 0 && values[0] is Tuple <Blending, ShaderId> )
            {
                ProcessBlendingAndShaderAnimators(node, animator);
            }
            else
            {
                for (int i = 0; i < frames.Count; i++)
                {
                    animator.Keys.Add(frames[i], values[i], functions[i]);
                }
            }
            switch (propertyName + '@' + className)
            {
            case "AspectRatio@Hot::ParticleTemplate":
                particleModifierAspectRatioAnimator = animator as NumericAnimator;
                break;

            case "Scale@Hot::ParticleTemplate":
                particleModifierScaleAnimator = animator as NumericAnimator;
                break;
            }
            if (animator.ReadonlyKeys.Count == 0)
            {
                node.Animators.Remove(animator);
            }
        }
예제 #30
0
        public static async Task <bool> Run(VerifyOptions options)
        {
            ISignatureAlgorithm signatureAlgorithm;

            if (string.IsNullOrEmpty(options.KeyType) || options.KeyType.Equals("RSA", StringComparison.OrdinalIgnoreCase))
            {
                signatureAlgorithm = RSASignatureAlgorithm.CreateForVerification(HashAlgorithmName.SHA512, KeyReader.ReadRSA(options.PublicKey));
            }
            else if (options.KeyType.Equals("P256", StringComparison.OrdinalIgnoreCase) || options.KeyType.Equals("ECDSA", StringComparison.OrdinalIgnoreCase))
            {
                signatureAlgorithm = ECDsaSignatureAlgorithm.CreateForVerification(HashAlgorithmName.SHA512, KeyReader.ReadECDsaPublic(options.PublicKey));
            }
            else if (options.KeyType.Equals("HMAC", StringComparison.OrdinalIgnoreCase))
            {
                signatureAlgorithm = SignatureAlgorithm.CreateForVerification(options.PublicKey, HashAlgorithmName.SHA512);
            }
            else
            {
                throw new NotSupportedException("The specified key type is not supported.");
            }

            var serviceProvider = new ServiceCollection()
                                  .AddHttpMessageSignatureVerification(provider => {
                var clientStore = new InMemoryClientStore();
                clientStore.Register(new Client(
                                         new KeyId("test"),
                                         "ConformanceClient",
                                         signatureAlgorithm,
                                         TimeSpan.FromSeconds(30),
                                         TimeSpan.FromMinutes(1)));
                return(clientStore);
            })
                                  .BuildServiceProvider();

            var verifier = serviceProvider.GetRequiredService <IRequestSignatureVerifier>();

            var verificationResult = await verifier.VerifySignature(options.Message, new SignedRequestAuthenticationOptions {
                OnSignatureParsed = options.ModifyParsedSignature
            });

            return(verificationResult is RequestSignatureVerificationResultSuccess);
        }