You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pl...@apache.org on 2015/12/07 04:33:48 UTC
[18/26] directory-kerby git commit: ASN1. Allowing to return a header
ASN1. Allowing to return a header
Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/4c7a8c44
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/4c7a8c44
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/4c7a8c44
Branch: refs/heads/pkinit-support
Commit: 4c7a8c4411fb1d3d6f619b8379b75ea431e8da6c
Parents: 7c93f2e
Author: Kai Zheng <ka...@intel.com>
Authored: Thu Dec 3 22:00:21 2015 +0800
Committer: Kai Zheng <ka...@intel.com>
Committed: Thu Dec 3 22:00:21 2015 +0800
----------------------------------------------------------------------
.../java/org/apache/kerby/asn1/Asn1Header.java | 54 +++++++++
.../java/org/apache/kerby/asn1/Asn1Reader.java | 111 +++++++++++++++++++
.../java/org/apache/kerby/asn1/Asn1Reader1.java | 47 ++++++++
.../java/org/apache/kerby/asn1/Asn1Reader2.java | 62 +++++++++++
.../java/org/apache/kerby/asn1/Asn1Util.java | 81 --------------
.../main/java/org/apache/kerby/asn1/Tag.java | 9 +-
.../org/apache/kerby/asn1/UniversalTag.java | 4 +-
.../org/apache/kerby/asn1/type/Asn1Eoc.java | 54 +++++++++
.../org/apache/kerby/asn1/type/Asn1Object.java | 58 ++++------
.../apache/kerby/kerberos/kerb/KrbCodec.java | 12 +-
10 files changed, 361 insertions(+), 131 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Header.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Header.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Header.java
new file mode 100644
index 0000000..0fbd047
--- /dev/null
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Header.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.kerby.asn1;
+
+import java.nio.ByteBuffer;
+
+public class Asn1Header {
+ private Tag tag;
+ private int length;
+ private ByteBuffer valueBuffer;
+
+ public Asn1Header(Tag tag, int length, ByteBuffer valueBuffer) {
+ this.tag = tag;
+ this.length = length;
+ this.valueBuffer = valueBuffer;
+ }
+
+ public Tag getTag() {
+ return tag;
+ }
+
+ public int getLength() {
+ return length;
+ }
+
+ public ByteBuffer getValueBuffer() {
+ return valueBuffer;
+ }
+
+ public boolean isEOC() {
+ return length == 0 && tag.isEOC();
+ }
+
+ public boolean isDefinitiveLength() {
+ return length != -1;
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader.java
new file mode 100644
index 0000000..9ee9819
--- /dev/null
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.kerby.asn1;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * ASN1 reader from a byte buffer.
+ */
+public abstract class Asn1Reader {
+ protected ByteBuffer buffer;
+
+ public Asn1Reader(ByteBuffer buffer) {
+ this.buffer = buffer;
+ }
+
+ public ByteBuffer getBuffer() {
+ return buffer;
+ }
+
+ public Asn1Header readHeader() throws IOException {
+ Tag tag = readTag();
+ int valueLength = readLength();
+ Asn1Header header = new Asn1Header(tag, valueLength,
+ getValueBuffer(valueLength));
+ return header;
+ }
+
+ protected abstract ByteBuffer getValueBuffer(int valueLength);
+
+ protected abstract byte readByte() throws IOException;
+
+ private Tag readTag() throws IOException {
+ int tagFlags = readTagFlags();
+ int tagNo = readTagNo(tagFlags);
+ return new Tag(tagFlags, tagNo);
+ }
+
+ private int readTagFlags() throws IOException {
+ int tagFlags = readByte() & 0xff;
+ return tagFlags;
+ }
+
+ private int readTagNo(int tagFlags) throws IOException {
+ int tagNo = tagFlags & 0x1f;
+
+ if (tagNo == 0x1f) {
+ tagNo = 0;
+
+ int b = readByte() & 0xff;
+ if ((b & 0x7f) == 0) {
+ throw new IOException("Invalid high tag number found");
+ }
+
+ while (b >= 0 && (b & 0x80) != 0) {
+ tagNo |= b & 0x7f;
+ tagNo <<= 7;
+ b = readByte();
+ }
+
+ tagNo |= b & 0x7f;
+ }
+
+ return tagNo;
+ }
+
+ private int readLength() throws IOException {
+ int result = readByte() & 0xff;
+ if (result == 0x80) {
+ return -1; // non-definitive length
+ }
+
+ if (result > 127) {
+ int length = result & 0x7f;
+ if (length > 4) {
+ throw new IOException("Bad length of more than 4 bytes: " + length);
+ }
+
+ result = 0;
+ int tmp;
+ for (int i = 0; i < length; i++) {
+ tmp = readByte() & 0xff;
+ result = (result << 8) + tmp;
+ }
+ }
+
+ if (result < 0) {
+ throw new IOException("Invalid length " + result);
+ }
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader1.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader1.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader1.java
new file mode 100644
index 0000000..291756d
--- /dev/null
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader1.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.kerby.asn1;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * ASN1 reader for stateful reading.
+ */
+public final class Asn1Reader1 extends Asn1Reader {
+
+ public Asn1Reader1(ByteBuffer buffer) {
+ super(buffer);
+ }
+
+ @Override
+ protected byte readByte() throws IOException {
+ return buffer.get();
+ }
+
+ @Override
+ protected ByteBuffer getValueBuffer(int valueLength) {
+ ByteBuffer result = buffer.duplicate();
+ result.limit(buffer.position() + valueLength);
+ buffer.position(buffer.position() + valueLength);
+
+ return result;
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader2.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader2.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader2.java
new file mode 100644
index 0000000..08e3472
--- /dev/null
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Reader2.java
@@ -0,0 +1,62 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.kerby.asn1;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * ASN1 reader for positional reading.
+ */
+public final class Asn1Reader2 extends Asn1Reader {
+ private int position;
+
+ public Asn1Reader2(ByteBuffer buffer, int position) {
+ super(buffer);
+ this.position = position;
+ }
+
+ public Asn1Reader2(ByteBuffer buffer) {
+ super(buffer);
+ this.position = buffer.position();
+ }
+
+ public int getPosition() {
+ return position;
+ }
+
+ public void setPosition(int position) {
+ this.position = position;
+ }
+
+ public boolean available() {
+ return position < buffer.limit();
+ }
+
+ @Override
+ protected ByteBuffer getValueBuffer(int valueLength) {
+ return buffer;
+ }
+
+ @Override
+ protected byte readByte() throws IOException {
+ return buffer.get(position++);
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Util.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Util.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Util.java
index caa50f3..315cf28 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Util.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Asn1Util.java
@@ -19,7 +19,6 @@
*/
package org.apache.kerby.asn1;
-import java.io.IOException;
import java.nio.ByteBuffer;
/**
@@ -110,86 +109,6 @@ public final class Asn1Util {
}
}
- public static Tag readTag(ByteBuffer buffer) throws IOException {
- int tagFlags = readTagFlags(buffer);
- int tagNo = readTagNo(buffer, tagFlags);
- return new Tag(tagFlags, tagNo);
- }
-
- private static int readTagFlags(ByteBuffer buffer) throws IOException {
- int tagFlags = buffer.get() & 0xff;
- if (tagFlags == 0) {
- throw new IOException("Bad tag 0 found");
- }
- return tagFlags;
- }
-
- private static int readTagNo(ByteBuffer buffer, int tagFlags) throws IOException {
- int tagNo = tagFlags & 0x1f;
-
- if (tagNo == 0x1f) {
- tagNo = 0;
-
- int b = buffer.get() & 0xff;
- if ((b & 0x7f) == 0) {
- throw new IOException("Invalid high tag number found");
- }
-
- while (b >= 0 && (b & 0x80) != 0) {
- tagNo |= b & 0x7f;
- tagNo <<= 7;
- b = buffer.get();
- }
-
- tagNo |= b & 0x7f;
- }
-
- return tagNo;
- }
-
- public static int readLength(ByteBuffer buffer) throws IOException {
- int result = buffer.get() & 0xff;
- if (result == 0x80) {
- return -1; // non-definitive length
- }
-
- if (result > 127) {
- int length = result & 0x7f;
- if (length > 4) {
- throw new IOException("Bad length of more than 4 bytes: " + length);
- }
-
- result = 0;
- int tmp;
- for (int i = 0; i < length; i++) {
- tmp = buffer.get() & 0xff;
- result = (result << 8) + tmp;
- }
- }
-
- if (result < 0) {
- throw new IOException("Invalid length " + result);
- }
-
- if (result > buffer.remaining()) {
- throw new IOException("Corrupt stream - less data "
- + buffer.remaining() + " than expected " + result);
- }
-
- return result;
- }
-
- public static ByteBuffer dupWithLength(ByteBuffer buffer, int length) {
- try {
- ByteBuffer result = buffer.duplicate();
- result.limit(buffer.position() + length);
- buffer.position(buffer.position() + length);
- return result;
- } catch (Exception e) {
- throw e;
- }
- }
-
public static byte[] readAllLeftBytes(ByteBuffer buffer) {
byte[] result = new byte[buffer.remaining()];
buffer.get(result);
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java
index bea843f..2cf5e6b 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/Tag.java
@@ -81,6 +81,10 @@ public class Tag {
return UniversalTag.UNKNOWN;
}
+ public boolean isEOC() {
+ return universalTag() == UniversalTag.EOC;
+ }
+
public boolean isUniversal() {
return tagClass().isUniversal();
}
@@ -124,10 +128,7 @@ public class Tag {
@Override
public String toString() {
- return "Tag["
- + "tagFlags=" + tagFlags
- + ", tagNo=" + tagNo
- + ']';
+ return tagNo >= 0x1F ? "N/A" : "" + (tagFlags | tagNo);
}
public static Tag newAppTag(int tagNo) {
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/UniversalTag.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/UniversalTag.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/UniversalTag.java
index e78b50e..0a2eef7 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/UniversalTag.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/UniversalTag.java
@@ -28,7 +28,7 @@ public enum UniversalTag {
UNKNOWN (-1),
CHOICE (-2), // Only for internal using
ANY (-3), // Only for internal using
- BER_UNDEFINED_LENGTH(0), // Used to encode undefined length with BER
+ EOC (0), // End of content, use by BER
BOOLEAN (0x01),
INTEGER (0x02),
BIT_STRING (0x03),
@@ -87,7 +87,7 @@ public enum UniversalTag {
*/
public static UniversalTag fromValue(int value) {
switch (value) {
- case 0x00 : return BER_UNDEFINED_LENGTH;
+ case 0x00 : return EOC;
case 0x01 : return BOOLEAN;
case 0x02 : return INTEGER;
case 0x03 : return BIT_STRING;
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Eoc.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Eoc.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Eoc.java
new file mode 100644
index 0000000..fe80979
--- /dev/null
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Eoc.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.kerby.asn1.type;
+
+import org.apache.kerby.asn1.UniversalTag;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * To represent Asn1 End Of Content type
+ */
+public final class Asn1Eoc extends Asn1Simple<Object> {
+ public static final Asn1Eoc INSTANCE = new Asn1Eoc();
+ private static final byte[] EMPTY_BYTES = new byte[0];
+
+ private Asn1Eoc() {
+ super(UniversalTag.EOC, null);
+ }
+
+ @Override
+ protected byte[] encodeBody() {
+ return EMPTY_BYTES;
+ }
+
+ @Override
+ protected int encodingBodyLength() {
+ return 0;
+ }
+
+ @Override
+ protected void decodeBody(ByteBuffer content) throws IOException {
+ if (content.remaining() != 0) {
+ throw new IOException("Unexpected bytes found for EOC");
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
index 0a46d37..099bf3f 100644
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
+++ b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
@@ -19,6 +19,8 @@
*/
package org.apache.kerby.asn1.type;
+import org.apache.kerby.asn1.Asn1Header;
+import org.apache.kerby.asn1.Asn1Reader1;
import org.apache.kerby.asn1.Asn1Util;
import org.apache.kerby.asn1.Tag;
import org.apache.kerby.asn1.TaggingOption;
@@ -198,19 +200,11 @@ public abstract class Asn1Object implements Asn1Type {
@Override
public void decode(ByteBuffer content) throws IOException {
- Tag tmpTag = Asn1Util.readTag(content);
- int length = Asn1Util.readLength(content);
+ Asn1Reader1 reader = new Asn1Reader1(content);
+ Asn1Header header = reader.readHeader();
- ByteBuffer valueBuffer;
- if (length == -1) {
- valueBuffer = content;
- useDefinitiveLength(false);
- } else {
- valueBuffer = Asn1Util.dupWithLength(content, length);
- useDefinitiveLength(true);
- }
-
- decode(tmpTag, valueBuffer);
+ useDefinitiveLength(header.isDefinitiveLength());
+ decode(header.getTag(), header.getValueBuffer());
}
public void decode(Tag tag, ByteBuffer content) throws IOException {
@@ -262,19 +256,11 @@ public abstract class Asn1Object implements Asn1Type {
@Override
public void taggedDecode(ByteBuffer content,
TaggingOption taggingOption) throws IOException {
- Tag taggingTag = Asn1Util.readTag(content);
- int taggingLength = Asn1Util.readLength(content);
-
- ByteBuffer valueBuffer;
- if (taggingLength == -1) {
- valueBuffer = content;
- useDefinitiveLength(false);
- } else {
- valueBuffer = Asn1Util.dupWithLength(content, taggingLength);
- useDefinitiveLength(true);
- }
+ Asn1Reader1 reader = new Asn1Reader1(content);
+ Asn1Header header = reader.readHeader();
- taggedDecode(taggingTag, valueBuffer, taggingOption);
+ useDefinitiveLength(header.isDefinitiveLength());
+ taggedDecode(header.getTag(), header.getValueBuffer(), taggingOption);
}
protected void taggedDecode(Tag taggingTag, ByteBuffer content,
@@ -292,21 +278,17 @@ public abstract class Asn1Object implements Asn1Type {
}
}
+ public static Asn1Header readHeader(ByteBuffer content) throws IOException {
+ Asn1Reader1 reader = new Asn1Reader1(content);
+ return reader.readHeader();
+ }
+
public static Asn1Item decodeOne(ByteBuffer content) throws IOException {
- Tag tmpTag = Asn1Util.readTag(content);
- int length = Asn1Util.readLength(content);
-
- Asn1Item result;
- ByteBuffer valueBuffer;
- if (length == -1) {
- result = new Asn1Item(tmpTag);
- result.useDefinitiveLength(false);
- result.setBodyContent(content);
- } else {
- valueBuffer = Asn1Util.dupWithLength(content, length);
- result = new Asn1Item(tmpTag, valueBuffer);
- result.useDefinitiveLength(true);
- }
+ Asn1Reader1 reader = new Asn1Reader1(content);
+ Asn1Header header = reader.readHeader();
+
+ Asn1Item result = new Asn1Item(header.getTag(), header.getValueBuffer());
+ result.useDefinitiveLength(header.isDefinitiveLength());
return result;
}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/4c7a8c44/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbCodec.java
----------------------------------------------------------------------
diff --git a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbCodec.java b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbCodec.java
index 5157cdc..96819b8 100644
--- a/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbCodec.java
+++ b/kerby-kerb/kerb-core/src/main/java/org/apache/kerby/kerberos/kerb/KrbCodec.java
@@ -19,8 +19,9 @@
*/
package org.apache.kerby.kerberos.kerb;
-import org.apache.kerby.asn1.Asn1Util;
+import org.apache.kerby.asn1.Asn1Header;
import org.apache.kerby.asn1.Tag;
+import org.apache.kerby.asn1.type.Asn1Object;
import org.apache.kerby.asn1.type.Asn1Type;
import org.apache.kerby.kerberos.kerb.type.ap.ApReq;
import org.apache.kerby.kerberos.kerb.type.base.KrbError;
@@ -63,10 +64,9 @@ public class KrbCodec {
return (T) implObj;
}
- public static KrbMessage decodeMessage(ByteBuffer byteBuffer) throws IOException {
- Tag tag = Asn1Util.readTag(byteBuffer);
- int length = Asn1Util.readLength(byteBuffer);
- ByteBuffer valueBuffer = Asn1Util.dupWithLength(byteBuffer, length);
+ public static KrbMessage decodeMessage(ByteBuffer buffer) throws IOException {
+ Asn1Header header = Asn1Object.readHeader(buffer);
+ Tag tag = header.getTag();
KrbMessage msg;
KrbMessageType msgType = KrbMessageType.fromValue(tag.tagNo());
@@ -87,7 +87,7 @@ public class KrbCodec {
} else {
throw new IOException("To be supported krb message type with tag: " + tag);
}
- msg.decode(tag, valueBuffer);
+ msg.decode(tag, header.getValueBuffer());
return msg;
}