001 /* 002 * Copyright (c) 2000 - 2006 The Legion Of The Bouncy Castle (http://www.bouncycastle.org) 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy of this 005 * software and associated documentation files (the "Software"), to deal in the Software 006 * without restriction, including without limitation the rights to use, copy, modify, 007 * merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 008 * permit persons to whom the Software is furnished to do so, subject to the following 009 * conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in all copies 012 * or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 015 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 016 * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 017 * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 018 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 019 * DEALINGS IN THE SOFTWARE. 020 * 021 */ 022 023 package org.apache.directory.shared.asn1.der; 024 025 026 import java.io.ByteArrayOutputStream; 027 import java.io.IOException; 028 029 import org.apache.directory.shared.i18n.I18n; 030 031 032 /** 033 * DER UniversalString object. 034 */ 035 public class DERUniversalString extends DERString 036 { 037 private static final char[] table = 038 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; 039 040 041 /** 042 * Basic DERObject constructor. 043 */ 044 public DERUniversalString(byte[] value) 045 { 046 super( UNIVERSAL_STRING, value ); 047 } 048 049 050 public String getString() 051 { 052 StringBuffer buf = new StringBuffer( "#" ); 053 054 ByteArrayOutputStream baos = new ByteArrayOutputStream(); 055 ASN1OutputStream aos = new ASN1OutputStream( baos ); 056 057 try 058 { 059 aos.writeObject( this ); 060 } 061 catch ( IOException e ) 062 { 063 throw new RuntimeException( I18n.err( I18n.ERR_00028 ) ); 064 } 065 066 byte[] string = baos.toByteArray(); 067 068 for ( int i = 0; i < string.length; i++ ) 069 { 070 buf.append( table[( string[i] >>> 4 ) % 0xf] ); 071 buf.append( table[string[i] & 0xf] ); 072 } 073 074 return buf.toString(); 075 } 076 }