001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Vladimir N. Molotkov
020: * @version $Revision$
021: */package java.security.cert;
022:
023: import java.io.IOException;
024:
025: import org.apache.harmony.security.asn1.ObjectIdentifier;
026: import org.apache.harmony.security.internal.nls.Messages;
027: import org.apache.harmony.security.utils.Array;
028:
029: /**
030: * @com.intel.drl.spec_ref
031: *
032: */
033: public class PolicyQualifierInfo {
034: // This PolicyQualifierInfo DER encoding
035: private final byte[] encoded;
036: // This PolicyQualifierInfo policy qualifier id -
037: // OID represented as String containing non-negative integers
038: // separated by periods
039: private final String policyQualifierId;
040: // DER encoding of the policy qualifier - part of encoded
041: private final byte[] policyQualifier;
042:
043: /**
044: * @com.intel.drl.spec_ref
045: */
046: public PolicyQualifierInfo(byte[] encoded) throws IOException {
047: if (encoded == null) {
048: throw new NullPointerException(Messages
049: .getString("security.0A")); //$NON-NLS-1$
050: }
051: if (encoded.length == 0) {
052: throw new IOException(Messages.getString("security.69")); //$NON-NLS-1$
053: }
054: this .encoded = new byte[encoded.length];
055: System.arraycopy(encoded, 0, this .encoded, 0,
056: this .encoded.length);
057:
058: // DER Decoding:
059: Object[] decoded = (Object[]) org.apache.harmony.security.x509.PolicyQualifierInfo.ASN1
060: .decode(this .encoded);
061: policyQualifierId = ObjectIdentifier
062: .toString((int[]) decoded[0]);
063: policyQualifier = (byte[]) decoded[1];
064: }
065:
066: /**
067: * @com.intel.drl.spec_ref
068: */
069: public final byte[] getEncoded() {
070: byte[] ret = new byte[encoded.length];
071: System.arraycopy(encoded, 0, ret, 0, encoded.length);
072: return ret;
073: }
074:
075: /**
076: * @com.intel.drl.spec_ref
077: */
078: public final String getPolicyQualifierId() {
079: return policyQualifierId;
080: }
081:
082: /**
083: * @com.intel.drl.spec_ref
084: */
085: public final byte[] getPolicyQualifier() {
086: if (policyQualifier == null) {
087: return null;
088: }
089: byte[] ret = new byte[policyQualifier.length];
090: System.arraycopy(policyQualifier, 0, ret, 0,
091: policyQualifier.length);
092: return ret;
093: }
094:
095: /**
096: * @com.intel.drl.spec_ref
097: */
098: public String toString() {
099: StringBuffer sb = new StringBuffer(
100: "PolicyQualifierInfo: [\npolicyQualifierId: "); //$NON-NLS-1$
101: sb.append(policyQualifierId);
102: sb.append("\npolicyQualifier: \n"); //$NON-NLS-1$
103: sb.append(Array.toString(policyQualifier, " ")); //$NON-NLS-1$
104: sb.append("]"); //$NON-NLS-1$
105: return sb.toString();
106: }
107: }
|