package com.inductiveautomation.opcua.stack.core.security;

import javax.crypto.Cipher;
import javax.crypto.Mac;
import java.security.MessageDigest;
import java.security.Signature;

public enum SecurityAlgorithm {

    None("", ""),

    /**
     * Symmetric Signature; transformation to be used with {@link Mac#getInstance(String)}.
     */
    HmacSha1("http://www.w3.org/2000/09/xmldsig#hmac-sha1", "HmacSHA1"),

    /**
     * Symmetric Signature; transformation to be used with {@link Mac#getInstance(String)}.
     */
    HmacSha256("http://www.w3.org/2000/09/xmldsig#hmac-sha256", "HmacSHA256"),

    /**
     * Symmetric Encryption; transformation to be used with {@link Cipher#getInstance(String)}.
     */
    Aes128("http://www.w3.org/2001/04/xmlenc#aes128-cbc", "AES/CBC/NoPadding"),

    /**
     * Symmetric Encryption; transformation to be used with {@link Cipher#getInstance(String)}.
     */
    Aes256("http://www.w3.org/2001/04/xmlenc#aes256-cbc", "AES/CBC/NoPadding"),

    /**
     * Asymmetric Signature; transformation to be used with {@link Signature#getInstance(String)}.
     */
    RsaSha1("http://www.w3.org/2000/09/xmldsig#rsa-sha1", "SHA1withRSA"),

    /**
     * Asymmetric Signature; transformation to be used with {@link Signature#getInstance(String)}.
     */
    RsaSha256("http://www.w3.org/2000/09/xmldsig#rsa-sha256", "SHA256withRSA"),

    /**
     * Asymmetric Encryption; transformation to be used with {@link Cipher#getInstance(String)}.
     */
    Rsa15("http://www.w3.org/2001/04/xmlenc#rsa-1_5", "RSA/ECB/PKCS1Padding"),

    /**
     * Asymmetric Encryption; transformation to be used with {@link Cipher#getInstance(String)}.
     */
    RsaOaep("http://www.w3.org/2001/04/xmlenc#rsa-oaep", "RSA/ECB/OAEPWithSHA-1AndMGF1Padding"),

    /**
     * Asymmetric Key Wrap
     */
    KwRsa15("http://www.w3.org/2001/04/xmlenc#rsa-1_5", ""),

    /**
     * Asymmetric Key Wrap
     */
    KwRsaOaep("http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p", ""),

    /**
     * Key Derivation
     */
    PSha1("http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512/dk/p_sha1", ""),

    /**
     * Key Derivation
     */
    PSha256("http://docs.oasis-open.org/ws-sx/ws-secureconversation/200512/dk/p_sha256", ""),

    /**
     * Cryptographic Hash; transformation to be used with {@link MessageDigest#getInstance(String)}.
     */
    Sha1("http://www.w3.org/2000/09/xmldsig#sha1", "SHA-1"),

    /**
     * Cryptographic Hash; transformation to be used with {@link MessageDigest#getInstance(String)}.
     */
    Sha256("http://www.w3.org/2001/04/xmlenc#sha256", "SHA-256");

    private final String uri;
    private final String transformation;

    SecurityAlgorithm(String uri, String transformation) {
        this.uri = uri;
        this.transformation = transformation;
    }

    /**
     * @return The URI identifying this security algorithm.
     */
    public String getUri() {
        return uri;
    }

    /**
     * @return The transformation string to use with the appropriate provider SPI.
     */
    public String getTransformation() {
        return transformation;
    }

}

@@ -175,16 +175,139 @@
 ature;%0A%0A
+import com.inductiveautomation.opcua.stack.core.StatusCodes;%0Aimport com.inductiveautomation.opcua.stack.core.UaException;%0A%0A
 public e
@@ -3257,10 +3257,433 @@
 %0A    %7D%0A%0A
+    public static SecurityAlgorithm fromUri(String securityAlgorithmUri) throws UaException %7B%0A        for (SecurityAlgorithm algorithm: values()) %7B%0A            if (algorithm.getUri().equals(securityAlgorithmUri)) %7B%0A                return algorithm;%0A            %7D%0A        %7D%0A%0A        throw new UaException(StatusCodes.Bad_SecurityChecksFailed,%0A                %22unknown securityAlgorithmUri: %22 + securityAlgorithmUri);%0A    %7D%0A%0A
 %7D%0A

Implement SecurityAlgorithm.fromUri()