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 18/** 19* @author Vladimir N. Molotkov, Stepan M. Mishura 20* @version $Revision$ 21*/ 22 23package org.apache.harmony.security.asn1; 24 25import java.io.IOException; 26 27 28/** 29 * This class represents ASN.1 Boolean type. 30 * 31 * @see <a href="http://asn1.elibel.tm.fr/en/standards/index.htm">ASN.1</a> 32 */ 33 34public class ASN1Boolean extends ASN1Primitive { 35 36 // default implementation 37 private static final ASN1Boolean ASN1 = new ASN1Boolean(); 38 39 /** 40 * Constructs ASN.1 Boolean type 41 * 42 * The constructor is provided for inheritance purposes 43 * when there is a need to create a custom ASN.1 Boolean type. 44 * To get a default implementation it is recommended to use 45 * getInstance() method. 46 */ 47 public ASN1Boolean() { 48 super(TAG_BOOLEAN); 49 } 50 51 /** 52 * Returns ASN.1 Boolean type default implementation 53 * 54 * The default implementation works with encoding 55 * that is represented as Boolean object. 56 * 57 * @return ASN.1 Boolean type default implementation 58 */ 59 public static ASN1Boolean getInstance() { 60 return ASN1; 61 } 62 63 // 64 // 65 // Decode 66 // 67 // 68 69 public Object decode(BerInputStream in) throws IOException { 70 in.readBoolean(); 71 72 if (in.isVerify) { 73 return null; 74 } 75 return getDecodedObject(in); 76 } 77 78 /** 79 * Extracts Boolean object from BER input stream. 80 * 81 * @param in - BER input stream 82 * @return java.lang.Boolean object 83 */ 84 public Object getDecodedObject(BerInputStream in) throws IOException { 85 if (in.buffer[in.contentOffset] == 0) { 86 return Boolean.FALSE; 87 } 88 return Boolean.TRUE; 89 } 90 91 // 92 // 93 // Encode 94 // 95 // 96 97 public void encodeContent(BerOutputStream out) { 98 out.encodeBoolean(); 99 } 100 101 public void setEncodingContent(BerOutputStream out) { 102 out.length = 1; 103 } 104} 105