1 /*
2  * @(#) $Id: ASN1OctetString.java,v 1.3 2003/07/08 08:13:52 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10package org.jstk.asn1;
11
12public class ASN1OctetString extends ASN1Type {
13    private static char[] hexChars =
14        { '0', '1', '2', '3', '4', '5', '6', '7',
15          '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
16    public ASN1OctetString(){
17        super(UNIVERSAL, NONE, OCTET_STRING, OCTET_STRING);
18    }
19
20    public String toString(){
21        if (value == null)
22            return "ASN1OctetString: null";
23
24        StringBuffer sb = new StringBuffer();
25        for (int i = 0; i < value.length; i++){
26            byte cbyte = value[i];
27            sb.append(hexChars[(0x000000f0 & cbyte) >> 4]);
28            sb.append(hexChars[(0x0000000f & cbyte)]);
29        }
30        return "ASN1OctetString: " + sb.toString();
31    }
32
33    public static void main(String[] args){
34        byte[] bytes = { (byte)0xf1, (byte)0xc1 };
35        ASN1OctetString os = new ASN1OctetString();
36        os.setValue(bytes);
37        System.out.println(os.toString());
38    }
39}