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 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 Enumerated type. 30 * 31 * @see <a href="http://asn1.elibel.tm.fr/en/standards/index.htm">ASN.1</a> 32 */ 33 34public class ASN1Enumerated extends ASN1Primitive { 35 36 // default implementation 37 private static final ASN1Enumerated ASN1 = new ASN1Enumerated(); 38 39 /** 40 * Constructs ASN.1 Enumerated type 41 * 42 * The constructor is provided for inheritance purposes 43 * when there is a need to create a custom ASN.1 Enumerated type. 44 * To get a default implementation it is recommended to use 45 * getInstance() method. 46 */ 47 public ASN1Enumerated() { 48 super(TAG_ENUM); 49 } 50 51 /** 52 * Returns ASN.1 Enumerated type default implementation 53 * 54 * The default implementation works with encoding 55 * that is represented as byte array. 56 * 57 * @return ASN.1 Enumerated type default implementation 58 */ 59 public static ASN1Enumerated getInstance() { 60 return ASN1; 61 } 62 63 // 64 // 65 // Decode 66 // 67 // 68 69 public Object decode(BerInputStream in) throws IOException { 70 in.readEnumerated(); 71 72 if (in.isVerify) { 73 return null; 74 } 75 return getDecodedObject(in); 76 } 77 78 /** 79 * Extracts array of bytes from BER input stream. 80 * 81 * @param in - BER input stream 82 * @return array of bytes 83 */ 84 public Object getDecodedObject(BerInputStream in) throws IOException { 85 byte[] bytesEncoded = new byte[in.length]; 86 System.arraycopy(in.buffer, in.contentOffset, bytesEncoded, 0, 87 in.length); 88 return bytesEncoded; 89 } 90 91 // 92 // 93 // Encode 94 // 95 // 96 97 public void encodeContent(BerOutputStream out) { 98 out.encodeInteger(); 99 } 100 101 public void setEncodingContent(BerOutputStream out) { 102 out.length = ((byte[]) out.content).length; 103 } 104} 105