blob: b3426321697edfe6fab36a17423faba570774276 [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/. */
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08004package org.onosproject.xran.asn1lib.ber.types;
slowr60d4d102017-08-16 18:33:58 -07005
6import com.fasterxml.jackson.annotation.JsonIgnore;
7import com.fasterxml.jackson.annotation.JsonValue;
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -08008import org.onosproject.xran.asn1lib.ber.BerByteArrayOutputStream;
9import org.onosproject.xran.asn1lib.ber.BerLength;
10import org.onosproject.xran.asn1lib.ber.BerTag;
slowr60d4d102017-08-16 18:33:58 -070011
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;
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080020
21 @JsonIgnore public byte[] code = null;
slowr60d4d102017-08-16 18:33:58 -070022
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
Dimitrios Mavrommatis96b255a2017-12-06 13:09:25 -080066
slowr60d4d102017-08-16 18:33:58 -070067 @Override
68 public String toString() {
69 return "ASN1_NULL";
70 }
71
72}