1/*
2 *  Licensed to the Apache Software Foundation (ASF) under one or more
3 *  contributor license agreements.  See the NOTICE file distributed with
4 *  this work for additional information regarding copyright ownership.
5 *  The ASF licenses this file to You under the Apache License, Version 2.0
6 *  (the "License"); you may not use this file except in compliance with
7 *  the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 *  Unless required by applicable law or agreed to in writing, software
12 *  distributed under the License is distributed on an "AS IS" BASIS,
13 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 *  See the License for the specific language governing permissions and
15 *  limitations under the License.
16 */
17
18package org.apache.harmony.security.x509;
19
20import java.io.IOException;
21import java.math.BigInteger;
22import org.apache.harmony.security.asn1.ASN1Integer;
23
24/**
25 * InhibitAnyPolicy Certificate Extension (OID = 2.5.29.54)
26 * Its ASN.1 notation is as follows:
27 * <pre>
28 *  id-ce-inhibitAnyPolicy OBJECT IDENTIFIER ::=  { id-ce 54 }
29 *
30 *  InhibitAnyPolicy ::= SkipCerts
31 *
32 *  SkipCerts ::= INTEGER (0..MAX)
33 * </pre>
34 * (as specified in RFC 3280 http://www.ietf.org/rfc/rfc3280.txt).
35 */
36public class InhibitAnyPolicy extends ExtensionValue {
37
38    // the value of the extension
39    private int skipCerts;
40
41    /**
42     * Create the object on the base of SkipCerts value.
43     */
44    public InhibitAnyPolicy(int skipCerts) {
45        this.skipCerts = skipCerts;
46    }
47
48    /**
49     * Creates an object on the base of its encoded form.
50     */
51    public InhibitAnyPolicy(byte[] encoding) throws IOException {
52        super(encoding);
53        this.skipCerts = new BigInteger((byte[])
54                ASN1Integer.getInstance().decode(encoding)).intValue();
55    }
56
57    /**
58     * Return the value of the extension.
59     */
60    public int getSkipCerts() {
61        return skipCerts;
62    }
63
64    /**
65     * Returns ASN.1 encoded form of the object.
66     * @return a byte array containing ASN.1 encoded form.
67     */
68    public byte[] getEncoded() {
69        if (encoding == null) {
70            encoding = ASN1Integer.getInstance()
71                .encode(ASN1Integer.fromIntValue(skipCerts));
72        }
73        return encoding;
74    }
75
76    /**
77     * Places the string representation of extension value
78     * into the StringBuffer object.
79     */
80    public void dumpValue(StringBuffer buffer, String prefix) {
81        buffer.append(prefix).append("Inhibit Any-Policy: ") //$NON-NLS-1$
82            .append(skipCerts).append('\n');
83    }
84}
85
86