예제 #1
0
        internal static KeyOptions FromJsonObject(JsonElement json)
        {
            KeyOptions ret = null;

            string kty = json.GetProperty(KeyTypePropertyName).GetString();

            switch (kty)
            {
            case CertificateKeyType.EC_HSM_KTY:
            case CertificateKeyType.EC_KTY:
                ret = new EcKeyOptions(kty);
                break;

            case CertificateKeyType.RSA_HSM_KTY:
            case CertificateKeyType.RSA_KTY:
                ret = new RsaKeyOptions(kty);
                break;
            }

            if (ret != null)
            {
                ((IJsonDeserializable)ret).ReadProperties(json);
            }

            return(ret);
        }
        void IJsonDeserializable.ReadProperties(JsonElement json)
        {
            foreach (JsonProperty prop in json.EnumerateObject())
            {
                switch (prop.Name)
                {
                case KeyPropsPropertyName:
                    KeyOptions.FromJsonObject(prop.Value);
                    break;

                case SecretPropsPropertyName:
                    ReadSecretProperties(prop.Value);
                    break;

                case X509PropsPropertyName:
                    ReadX509CertificateProperties(prop.Value);
                    break;

                case IssuerPropertyName:
                    ReadIssuerProperties(prop.Value);
                    break;

                case AttributesPropertyName:
                    ReadAttributesProperties(prop.Value);
                    break;

                case LifetimeActionsPropertyName:
                    LifetimeActions = new List <LifetimeAction>();
                    foreach (JsonElement actionElem in prop.Value.EnumerateArray())
                    {
                        LifetimeActions.Add(LifetimeAction.FromJsonObject(actionElem));
                    }
                    break;
                }
            }
        }
        void IJsonSerializable.WriteProperties(Utf8JsonWriter json)
        {
            // Key Props
            if (KeyOptions != null)
            {
                json.WriteStartObject(KeyPropsPropertyNameBytes);

                KeyOptions.WriteProperties(json);

                json.WriteEndObject();
            }

            // Secret Props
            if (ContentType.HasValue)
            {
                json.WriteStartObject(SecretPropsPropertyNameBytes);

                WriteSecretProperties(json);

                json.WriteEndObject();
            }

            // X509 Props
            if (Subject != null || SubjectAlternativeNames != null || KeyUsage != null || EnhancedKeyUsage != null || ValidityInMonths.HasValue)
            {
                json.WriteStartObject(X509PropsPropertyNameBytes);

                WriteX509CertificateProperties(json);

                json.WriteEndObject();
            }

            // Issuer Props
            if (IssuerName != null || CertificateType != null || CertificateTransparency.HasValue)
            {
                json.WriteStartObject(IssuerPropertyNameBytes);

                WriteIssuerProperties(json);

                json.WriteEndObject();
            }

            if (LifetimeActions != null)
            {
                json.WriteStartArray(LifetimeActionsPropertyNameBytes);

                foreach (var action in LifetimeActions)
                {
                    if (action != null)
                    {
                        json.WriteStartObject();

                        ((IJsonSerializable)action).WriteProperties(json);

                        json.WriteEndObject();
                    }
                }

                json.WriteEndArray();
            }
        }