Search in sources :

Example 1 with UsageType

use of org.xipki.ca.certprofile.x509.jaxb.UsageType in project xipki by xipki.

the class ProfileConfCreatorDemo method createKeyUsages.

private static ExtensionValueType createKeyUsages(KeyUsageEnum[] requiredUsages, KeyUsageEnum[] optionalUsages) {
    KeyUsage extValue = new KeyUsage();
    if (requiredUsages != null) {
        for (KeyUsageEnum m : requiredUsages) {
            UsageType usage = new UsageType();
            usage.setValue(m);
            usage.setRequired(true);
            extValue.getUsage().add(usage);
        }
    }
    if (optionalUsages != null) {
        for (KeyUsageEnum m : optionalUsages) {
            UsageType usage = new UsageType();
            usage.setValue(m);
            usage.setRequired(false);
            extValue.getUsage().add(usage);
        }
    }
    return createExtensionValueType(extValue);
}
Also used : KeyUsage(org.xipki.ca.certprofile.x509.jaxb.KeyUsage) ExtendedKeyUsage(org.xipki.ca.certprofile.x509.jaxb.ExtendedKeyUsage) UsageType(org.xipki.ca.certprofile.x509.jaxb.UsageType) KeyUsageEnum(org.xipki.ca.certprofile.x509.jaxb.KeyUsageEnum)

Example 2 with UsageType

use of org.xipki.ca.certprofile.x509.jaxb.UsageType in project xipki by xipki.

the class XmlX509CertprofileUtil method buildKeyUsageOptions.

// method toOidList
public static Set<KeyUsageControl> buildKeyUsageOptions(org.xipki.ca.certprofile.x509.jaxb.KeyUsage extConf) {
    ParamUtil.requireNonNull("extConf", extConf);
    List<UsageType> usages = extConf.getUsage();
    Set<KeyUsageControl> controls = new HashSet<>();
    for (UsageType m : usages) {
        boolean required = m.isRequired();
        switch(m.getValue()) {
            case CRL_SIGN:
                controls.add(new KeyUsageControl(KeyUsage.cRLSign, required));
                break;
            case DATA_ENCIPHERMENT:
                controls.add(new KeyUsageControl(KeyUsage.dataEncipherment, required));
                break;
            case CONTENT_COMMITMENT:
                controls.add(new KeyUsageControl(KeyUsage.contentCommitment, required));
                break;
            case DECIPHER_ONLY:
                controls.add(new KeyUsageControl(KeyUsage.decipherOnly, required));
                break;
            case ENCIPHER_ONLY:
                controls.add(new KeyUsageControl(KeyUsage.encipherOnly, required));
                break;
            case DIGITAL_SIGNATURE:
                controls.add(new KeyUsageControl(KeyUsage.digitalSignature, required));
                break;
            case KEY_AGREEMENT:
                controls.add(new KeyUsageControl(KeyUsage.keyAgreement, required));
                break;
            case KEY_CERT_SIGN:
                controls.add(new KeyUsageControl(KeyUsage.keyCertSign, required));
                break;
            case KEY_ENCIPHERMENT:
                controls.add(new KeyUsageControl(KeyUsage.keyEncipherment, required));
                break;
            default:
                throw new RuntimeException("should not reach here, unknown GeneralSubtreeBaseType " + m.getValue());
        }
    }
    return Collections.unmodifiableSet(controls);
}
Also used : KeyUsageControl(org.xipki.ca.api.profile.x509.KeyUsageControl) ExtKeyUsageControl(org.xipki.ca.api.profile.x509.ExtKeyUsageControl) UsageType(org.xipki.ca.certprofile.x509.jaxb.UsageType) HashSet(java.util.HashSet)

Aggregations

UsageType (org.xipki.ca.certprofile.x509.jaxb.UsageType)2 HashSet (java.util.HashSet)1 ExtKeyUsageControl (org.xipki.ca.api.profile.x509.ExtKeyUsageControl)1 KeyUsageControl (org.xipki.ca.api.profile.x509.KeyUsageControl)1 ExtendedKeyUsage (org.xipki.ca.certprofile.x509.jaxb.ExtendedKeyUsage)1 KeyUsage (org.xipki.ca.certprofile.x509.jaxb.KeyUsage)1 KeyUsageEnum (org.xipki.ca.certprofile.x509.jaxb.KeyUsageEnum)1