jdk/src/share/classes/sun/security/x509/CertificateExtensions.java
changeset 10336 0bb1999251f8
parent 5506 202f599c92aa
child 13040 1f31b09f711d
equal deleted inserted replaced
10335:3c7eda3ab2f5 10336:0bb1999251f8
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    91     private static Class[] PARAMS = {Boolean.class, Object.class};
    91     private static Class[] PARAMS = {Boolean.class, Object.class};
    92 
    92 
    93     // Parse the encoded extension
    93     // Parse the encoded extension
    94     private void parseExtension(Extension ext) throws IOException {
    94     private void parseExtension(Extension ext) throws IOException {
    95         try {
    95         try {
    96             Class extClass = OIDMap.getClass(ext.getExtensionId());
    96             Class<?> extClass = OIDMap.getClass(ext.getExtensionId());
    97             if (extClass == null) {   // Unsupported extension
    97             if (extClass == null) {   // Unsupported extension
    98                 if (ext.isCritical()) {
    98                 if (ext.isCritical()) {
    99                     unsupportedCritExt = true;
    99                     unsupportedCritExt = true;
   100                 }
   100                 }
   101                 if (map.put(ext.getExtensionId().toString(), ext) == null) {
   101                 if (map.put(ext.getExtensionId().toString(), ext) == null) {
   102                     return;
   102                     return;
   103                 } else {
   103                 } else {
   104                     throw new IOException("Duplicate extensions not allowed");
   104                     throw new IOException("Duplicate extensions not allowed");
   105                 }
   105                 }
   106             }
   106             }
   107             Constructor cons = ((Class<?>)extClass).getConstructor(PARAMS);
   107             Constructor<?> cons = extClass.getConstructor(PARAMS);
   108 
   108 
   109             Object[] passed = new Object[] {Boolean.valueOf(ext.isCritical()),
   109             Object[] passed = new Object[] {Boolean.valueOf(ext.isCritical()),
   110                     ext.getExtensionValue()};
   110                     ext.getExtensionValue()};
   111                     CertAttrSet certExt = (CertAttrSet)cons.newInstance(passed);
   111                     CertAttrSet<?> certExt = (CertAttrSet<?>)
       
   112                             cons.newInstance(passed);
   112                     if (map.put(certExt.getName(), (Extension)certExt) != null) {
   113                     if (map.put(certExt.getName(), (Extension)certExt) != null) {
   113                         throw new IOException("Duplicate extensions not allowed");
   114                         throw new IOException("Duplicate extensions not allowed");
   114                     }
   115                     }
   115         } catch (InvocationTargetException invk) {
   116         } catch (InvocationTargetException invk) {
   116             Throwable e = invk.getTargetException();
   117             Throwable e = invk.getTargetException();
   130                 return;
   131                 return;
   131             }
   132             }
   132             if (e instanceof IOException) {
   133             if (e instanceof IOException) {
   133                 throw (IOException)e;
   134                 throw (IOException)e;
   134             } else {
   135             } else {
   135                 throw (IOException)new IOException(e.toString()).initCause(e);
   136                 throw new IOException(e);
   136             }
   137             }
   137         } catch (IOException e) {
   138         } catch (IOException e) {
   138             throw e;
   139             throw e;
   139         } catch (Exception e) {
   140         } catch (Exception e) {
   140             throw (IOException)new IOException(e.toString()).initCause(e);
   141             throw new IOException(e);
   141         }
   142         }
   142     }
   143     }
   143 
   144 
   144     /**
   145     /**
   145      * Encode the extensions in DER form to the stream, setting
   146      * Encode the extensions in DER form to the stream, setting
   208     /**
   209     /**
   209      * Get the attribute value.
   210      * Get the attribute value.
   210      * @param name the extension name used in the lookup.
   211      * @param name the extension name used in the lookup.
   211      * @exception IOException if named extension is not found.
   212      * @exception IOException if named extension is not found.
   212      */
   213      */
   213     public Object get(String name) throws IOException {
   214     public Extension get(String name) throws IOException {
   214         Object obj = map.get(name);
   215         Extension obj = map.get(name);
   215         if (obj == null) {
   216         if (obj == null) {
   216             throw new IOException("No extension found with name " + name);
   217             throw new IOException("No extension found with name " + name);
   217         }
   218         }
   218         return (obj);
   219         return (obj);
   219     }
   220     }
   231         map.remove(name);
   232         map.remove(name);
   232     }
   233     }
   233 
   234 
   234     public String getNameByOid(ObjectIdentifier oid) throws IOException {
   235     public String getNameByOid(ObjectIdentifier oid) throws IOException {
   235         for (String name: map.keySet()) {
   236         for (String name: map.keySet()) {
   236             if (map.get(name).getExtensionId().equals(oid)) {
   237             if (map.get(name).getExtensionId().equals((Object)oid)) {
   237                 return name;
   238                 return name;
   238             }
   239             }
   239         }
   240         }
   240         return null;
   241         return null;
   241     }
   242     }
   351     public UnparseableExtension(Extension ext, Throwable why) {
   352     public UnparseableExtension(Extension ext, Throwable why) {
   352         super(ext);
   353         super(ext);
   353 
   354 
   354         name = "";
   355         name = "";
   355         try {
   356         try {
   356             Class extClass = OIDMap.getClass(ext.getExtensionId());
   357             Class<?> extClass = OIDMap.getClass(ext.getExtensionId());
   357             if (extClass != null) {
   358             if (extClass != null) {
   358                 Field field = extClass.getDeclaredField("NAME");
   359                 Field field = extClass.getDeclaredField("NAME");
   359                 name = (String)(field.get(null)) + " ";
   360                 name = (String)(field.get(null)) + " ";
   360             }
   361             }
   361         } catch (Exception e) {
   362         } catch (Exception e) {