From aaa8d03d36f31894fed3c8d9c7b5126ac5417774 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Wed, 1 Feb 2017 16:17:51 +1000 Subject: [PATCH 152/155] GeneralName: add method to get at inner value The 'GeneralNameInterface' interface represents a single X.509 General Name value. Various types are supported. The 'GeneralName' class (which also implements 'GeneralNameInterface') is a singleton container for another 'GeneralNameInterface' value. To implement a profile component that copies CN to a SAN dNSName, we need to examine existing General Names in the SAN extension (if present), to avoid duplicate values. We can iterate 'GeneralNames', but if the value is of type 'GeneralName' we need a way to "unwrap" the value, down to the innermost value which will be of a specific General Name type. Add the 'unwrap' method to 'GeneralName'. Part of: https://fedorahosted.org/pki/ticket/1710 --- base/util/src/netscape/security/x509/GeneralName.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/base/util/src/netscape/security/x509/GeneralName.java b/base/util/src/netscape/security/x509/GeneralName.java index a90ac7bf259b519c91bb2f67cf159f7b4178b182..55b5bfcf304c0c8ccf893f9a6ef70d2e5c2ee0e2 100644 --- a/base/util/src/netscape/security/x509/GeneralName.java +++ b/base/util/src/netscape/security/x509/GeneralName.java @@ -196,4 +196,19 @@ public class GeneralName implements GeneralNameInterface { constructedForm, (byte) nameType), tmp); } } + + /** + * Unwrap this GeneralName until we reach something that is not + * a GeneralName. + */ + public GeneralNameInterface unwrap() { + if (this == name) + return null; // can't happen, but just in case... + + if (name instanceof GeneralName) + return ((GeneralName) name).unwrap(); + else + return name; + } + } -- 2.9.3