Path: blob/master/src/java.base/share/classes/sun/security/x509/AccessDescription.java
41159 views
/*1* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.x509;2627import java.io.IOException;2829import sun.security.util.*;3031/**32* @author Ram Marti33*/3435public final class AccessDescription {3637private int myhash = -1;3839private ObjectIdentifier accessMethod;4041private GeneralName accessLocation;4243public static final ObjectIdentifier Ad_OCSP_Id =44ObjectIdentifier.of(KnownOIDs.OCSP);4546public static final ObjectIdentifier Ad_CAISSUERS_Id =47ObjectIdentifier.of(KnownOIDs.caIssuers);4849public static final ObjectIdentifier Ad_TIMESTAMPING_Id =50ObjectIdentifier.of(KnownOIDs.AD_TimeStamping);5152public static final ObjectIdentifier Ad_CAREPOSITORY_Id =53ObjectIdentifier.of(KnownOIDs.caRepository);5455public AccessDescription(ObjectIdentifier accessMethod, GeneralName accessLocation) {56this.accessMethod = accessMethod;57this.accessLocation = accessLocation;58}5960public AccessDescription(DerValue derValue) throws IOException {61DerInputStream derIn = derValue.getData();62accessMethod = derIn.getOID();63accessLocation = new GeneralName(derIn.getDerValue());64}6566public ObjectIdentifier getAccessMethod() {67return accessMethod;68}6970public GeneralName getAccessLocation() {71return accessLocation;72}7374public void encode(DerOutputStream out) throws IOException {75DerOutputStream tmp = new DerOutputStream();76tmp.putOID(accessMethod);77accessLocation.encode(tmp);78out.write(DerValue.tag_Sequence, tmp);79}8081public int hashCode() {82if (myhash == -1) {83myhash = accessMethod.hashCode() + accessLocation.hashCode();84}85return myhash;86}8788public boolean equals(Object obj) {89if (obj == null || (!(obj instanceof AccessDescription))) {90return false;91}92AccessDescription that = (AccessDescription)obj;9394if (this == that) {95return true;96}97return (accessMethod.equals(that.getAccessMethod()) &&98accessLocation.equals(that.getAccessLocation()));99}100101public String toString() {102String method = null;103if (accessMethod.equals(Ad_CAISSUERS_Id)) {104method = "caIssuers";105} else if (accessMethod.equals(Ad_CAREPOSITORY_Id)) {106method = "caRepository";107} else if (accessMethod.equals(Ad_TIMESTAMPING_Id)) {108method = "timeStamping";109} else if (accessMethod.equals(Ad_OCSP_Id)) {110method = "ocsp";111} else {112method = accessMethod.toString();113}114return ("\n accessMethod: " + method +115"\n accessLocation: " + accessLocation.toString() + "\n");116}117}118119120