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