blob: 6437d0bcb7afbd2a8794f90c8823d2569d9b6513 [file] [log] [blame]
slowr60d4d102017-08-16 18:33:58 -07001/* 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/. */
4package org.onosproject.xran.codecs.ber.types;
5
6import com.fasterxml.jackson.annotation.JsonIgnore;
7import com.fasterxml.jackson.annotation.JsonValue;
8import org.onosproject.xran.codecs.ber.BerByteArrayOutputStream;
9import org.onosproject.xran.codecs.ber.BerLength;
10import org.onosproject.xran.codecs.ber.BerTag;
11
12import java.io.IOException;
13import java.io.InputStream;
14import java.io.Serializable;
15
16public class BerNull implements Serializable {
17
18 public final static BerTag tag = new BerTag(BerTag.UNIVERSAL_CLASS, BerTag.PRIMITIVE, BerTag.NULL_TAG);
19 private static final long serialVersionUID = 1L;
20 @JsonIgnore
21 public byte[] code = null;
22
23 public BerNull() {
24 }
25
26 public BerNull(byte[] code) {
27 }
28
29 public int encode(BerByteArrayOutputStream os) throws IOException {
30 return encode(os, true);
31 }
32
33 public int encode(BerByteArrayOutputStream os, boolean withTag) throws IOException {
34
35 int codeLength = BerLength.encodeLength(os, 0);
36
37 if (withTag) {
38 codeLength += tag.encode(os);
39 }
40
41 return codeLength;
42 }
43
44 public int decode(InputStream is) throws IOException {
45 return decode(is, true);
46 }
47
48 public int decode(InputStream is, boolean withTag) throws IOException {
49
50 int codeLength = 0;
51
52 if (withTag) {
53 codeLength += tag.decodeAndCheck(is);
54 }
55
56 BerLength length = new BerLength();
57 codeLength += length.decode(is);
58
59 if (length.val != 0) {
60 throw new IOException("Decoded length of BerNull is not correct");
61 }
62
63 return codeLength;
64 }
65
66 @JsonValue
67 @Override
68 public String toString() {
69 return "ASN1_NULL";
70 }
71
72}