slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 4 | package org.onosproject.xran.asn1lib.ber.types.string; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 5 | |
| 6 | import com.fasterxml.jackson.annotation.JsonValue; |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 7 | import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream; |
| 8 | import org.onosproject.xran.asn1lib.ber.BerTag; |
| 9 | import org.onosproject.xran.asn1lib.ber.types.BerOctetString; |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 10 | |
| 11 | import java.io.IOException; |
| 12 | import java.io.InputStream; |
| 13 | |
| 14 | public class BerUniversalString extends BerOctetString { |
| 15 | |
| 16 | public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.UNIVERSAL_STRING_TAG); |
| 17 | private static final long serialVersionUID = 1L; |
| 18 | |
| 19 | public BerUniversalString() { |
| 20 | } |
| 21 | |
| 22 | public BerUniversalString(byte[] value) { |
| 23 | this.value = value; |
| 24 | } |
| 25 | |
Dimitrios Mavrommatis | 96b255a | 2017-12-06 13:09:25 -0800 | [diff] [blame] | 26 | |
slowr | 60d4d10 | 2017-08-16 18:33:58 -0700 | [diff] [blame] | 27 | @Override |
| 28 | public String toString() { |
| 29 | return new String(value); |
| 30 | } |
| 31 | |
| 32 | @Override |
| 33 | public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException { |
| 34 | |
| 35 | int codeLength = super.encode(os, false); |
| 36 | |
| 37 | if (withTag) { |
| 38 | codeLength += tag.encode(os); |
| 39 | } |
| 40 | |
| 41 | return codeLength; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public int decode(InputStream is, boolean withTag) throws IOException { |
| 46 | |
| 47 | int codeLength = 0; |
| 48 | |
| 49 | if (withTag) { |
| 50 | codeLength += tag.decodeAndCheck(is); |
| 51 | } |
| 52 | |
| 53 | codeLength += super.decode(is, false); |
| 54 | |
| 55 | return codeLength; |
| 56 | } |
| 57 | |
| 58 | } |