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, Stepan M. Mishura
020: * @version $Revision$
021: */package org.apache.harmony.security.asn1;
022:
023: import java.io.IOException;
024:
025: /**
026: * This class represents ASN.1 Boolean type.
027: *
028: * @see http://asn1.elibel.tm.fr/en/standards/index.htm
029: */
030:
031: public class ASN1Boolean extends ASN1Primitive {
032:
033: // default implementation
034: private static final ASN1Boolean ASN1 = new ASN1Boolean();
035:
036: /**
037: * Constructs ASN.1 Boolean type
038: *
039: * The constructor is provided for inheritance purposes
040: * when there is a need to create a custom ASN.1 Boolean type.
041: * To get a default implementation it is recommended to use
042: * getInstance() method.
043: */
044: public ASN1Boolean() {
045: super (TAG_BOOLEAN);
046: }
047:
048: /**
049: * Returns ASN.1 Boolean type default implementation
050: *
051: * The default implementation works with encoding
052: * that is represented as Boolean object.
053: *
054: * @return ASN.1 Boolean type default implementation
055: */
056: public static ASN1Boolean getInstance() {
057: return ASN1;
058: }
059:
060: //
061: //
062: // Decode
063: //
064: //
065:
066: public Object decode(BerInputStream in) throws IOException {
067: in.readBoolean();
068:
069: if (in.isVerify) {
070: return null;
071: }
072: return getDecodedObject(in);
073: }
074:
075: /**
076: * Extracts Boolean object from BER input stream.
077: *
078: * @param in - BER input stream
079: * @return java.lang.Boolean object
080: */
081: public Object getDecodedObject(BerInputStream in)
082: throws IOException {
083: if (in.buffer[in.contentOffset] == 0) {
084: return Boolean.FALSE;
085: }
086: return Boolean.TRUE;
087: }
088:
089: //
090: //
091: // Encode
092: //
093: //
094:
095: public void encodeContent(BerOutputStream out) {
096: out.encodeBoolean();
097: }
098:
099: public void setEncodingContent(BerOutputStream out) {
100: out.length = 1;
101: }
102: }
|