You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by dr...@apache.org on 2016/01/16 10:38:39 UTC
[11/13] directory-kerby git commit: Consolidated facility and support
modules into kerby-common
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java
deleted file mode 100644
index f5b0509..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Integer.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * 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.math.BigInteger;
-
-public class Asn1Integer extends Asn1Simple<BigInteger> {
- public Asn1Integer() {
- this((BigInteger) null);
- }
-
- public Asn1Integer(Integer value) {
- this(BigInteger.valueOf(value));
- }
-
- public Asn1Integer(Long value) {
- this(BigInteger.valueOf(value));
- }
-
- public Asn1Integer(BigInteger value) {
- super(UniversalTag.INTEGER, value);
- }
-
- protected void toBytes() {
- setBytes(getValue().toByteArray());
- }
-
- protected void toValue() throws IOException {
- setValue(new BigInteger(getBytes()));
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java
deleted file mode 100644
index b43bb4f..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Null.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**
- * 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 org.apache.kerby.asn1.parse.Asn1ParseResult;
-
-import java.io.IOException;
-
-/**
- * The Asn1 Null type
- */
-public final class Asn1Null extends Asn1Simple<Object> {
- public static final Asn1Null INSTANCE = new Asn1Null();
- private static final byte[] EMPTY_BYTES = new byte[0];
-
- private Asn1Null() {
- super(UniversalTag.NULL, null);
- }
-
- @Override
- protected byte[] encodeBody() {
- return EMPTY_BYTES;
- }
-
- @Override
- protected int encodingBodyLength() {
- return 0;
- }
-
- @Override
- protected void decodeBody(Asn1ParseResult parseResult) throws IOException {
- if (parseResult.getHeader().getLength() != 0) {
- throw new IOException("Unexpected bytes found for NULL");
- }
- }
-
- @Override
- public String toString() {
- String typeStr = tag().typeStr() + " ["
- + "tag=" + tag()
- + ", len=" + getHeaderLength() + "+" + getBodyLength()
- + "] ";
- return typeStr + "null";
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1NumericsString.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1NumericsString.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1NumericsString.java
deleted file mode 100644
index 3ef4ae1..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1NumericsString.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * 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;
-
-public class Asn1NumericsString extends Asn1String {
- public Asn1NumericsString() {
- this(null);
- }
-
- public Asn1NumericsString(String value) {
- super(UniversalTag.NUMERIC_STRING, value);
- if (value != null && !isNumeric(value)) {
- throw new IllegalArgumentException("Invalid numeric string");
- }
- }
-
- public static boolean isNumeric(String s) {
- for (int i = s.length() - 1; i >= 0; i--) {
- char c = s.charAt(i);
- if (!(c >= '0' && c <= '9' || c == ' ')) {
- return false;
- }
- }
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/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
deleted file mode 100644
index 4948828..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Object.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * 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.Tag;
-import org.apache.kerby.asn1.UniversalTag;
-
-import java.io.IOException;
-
-/**
- * An ASN1 object has a tag.
- */
-public abstract class Asn1Object {
-
- private final Tag tag;
-
- /**
- * Constructor with a tag
- * @param tag The tag
- */
- public Asn1Object(Tag tag) {
- this.tag = new Tag(tag);
- }
-
- /**
- * Default constructor with an universal tag.
- * @param tag the tag
- */
- public Asn1Object(UniversalTag tag) {
- this.tag = new Tag(tag);
- }
-
- /**
- * Constructor with a tag
- * @param tag The tag
- */
- public Asn1Object(int tag) {
- this.tag = new Tag(tag);
- }
-
- public Tag tag() {
- return tag;
- }
-
- public int tagFlags() {
- return tag().tagFlags();
- }
-
- public int tagNo() {
- return tag().tagNo();
- }
-
- public void usePrimitive(boolean isPrimitive) {
- tag().usePrimitive(isPrimitive);
- }
-
- public boolean isPrimitive() {
- return tag().isPrimitive();
- }
-
- public boolean isUniversal() {
- return tag().isUniversal();
- }
-
- public boolean isAppSpecific() {
- return tag().isAppSpecific();
- }
-
- public boolean isContextSpecific() {
- return tag().isContextSpecific();
- }
-
- public boolean isTagSpecific() {
- return tag().isSpecific();
- }
-
- public boolean isEOC() {
- return tag().isEOC();
- }
-
- public boolean isNull() {
- return tag().isNull();
- }
-
- public boolean isSimple() {
- return Asn1Simple.isSimple(tag());
- }
-
- public boolean isCollection() {
- return Asn1Collection.isCollection(tag());
- }
-
- protected abstract int getHeaderLength() throws IOException;
-
- protected abstract int getBodyLength() throws IOException;
-
- protected String simpleInfo() {
- String simpleInfo = tag().typeStr();
-
- try {
- simpleInfo += " ["
- + "tag=" + tag()
- + ", len=" + getHeaderLength() + "+" + getBodyLength()
- + "] ";
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
- return simpleInfo;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1ObjectIdentifier.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1ObjectIdentifier.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1ObjectIdentifier.java
deleted file mode 100644
index 9c4a9f7..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1ObjectIdentifier.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/**
- * 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.math.BigInteger;
-import java.nio.ByteBuffer;
-
-/**
- * ASN1 object identifier.
- */
-public class Asn1ObjectIdentifier extends Asn1Simple<String> {
- public Asn1ObjectIdentifier() {
- this(null);
- }
-
- public Asn1ObjectIdentifier(String value) {
- super(UniversalTag.OBJECT_IDENTIFIER, value);
- }
-
- @Override
- protected void toBytes() {
- byte[][] bytesArr = convert(getValue());
- int allLen = 0;
- for (byte[] bytes : bytesArr) {
- allLen += bytes.length;
- }
- ByteBuffer buffer = ByteBuffer.allocate(allLen);
- for (byte[] bytes : bytesArr) {
- buffer.put(bytes);
- }
- setBytes(buffer.array());
- }
-
- protected void toValue() {
- StringBuilder sb = new StringBuilder();
-
- byte[] bytes = getBytes();
- byte[][] bytesGroups = group(bytes);
- BigInteger[] coms = convert(bytesGroups);
-
- long first = coms[0].longValue();
- sb.append(first / 40).append('.');
- sb.append(first % 40);
- if (coms.length > 1) {
- sb.append('.');
- }
-
- for (int i = 1; i < coms.length; ++i) {
- sb.append(coms[i].toString());
- if (i != coms.length - 1) {
- sb.append('.');
- }
- }
-
- String value = sb.toString();
- setValue(value);
- }
-
- private BigInteger[] convert(byte[][] bytesGroups) {
- BigInteger[] comps = new BigInteger[bytesGroups.length];
-
- for (int i = 0; i < bytesGroups.length; ++i) {
- comps[i] = convert(bytesGroups[i]);
- }
-
- return comps;
- }
-
- private BigInteger convert(byte[] bytes) {
- BigInteger value = BigInteger.valueOf(bytes[0] & 0x7f);
- for (int i = 1; i < bytes.length; ++i) {
- value = value.shiftLeft(7);
- value = value.or(BigInteger.valueOf(bytes[i] & 0x7f));
- }
-
- return value;
- }
-
- /**
- * divide and group bytes together belonging to each component
- */
- private byte[][] group(byte[] bytes) {
- int count = 0, i, j;
- int[] countArr = new int[bytes.length]; // how many bytes for each group
- for (i = 0; i < countArr.length; ++i) {
- countArr[i] = 0;
- }
-
- for (j = 0, i = 0; i < bytes.length; ++i) {
- if ((bytes[i] & 0x80) != 0) {
- countArr[j]++;
- } else {
- countArr[j++]++;
- }
- }
- count = j;
-
- byte[][] bytesGroups = new byte[count][];
- for (i = 0; i < count; ++i) {
- bytesGroups[i] = new byte[countArr[i]];
- }
-
- int k = 0;
- for (j = 0, i = 0; i < bytes.length; ++i) {
- bytesGroups[j][k++] = bytes[i];
- if ((bytes[i] & 0x80) == 0) {
- j++;
- k = 0;
- }
- }
-
- return bytesGroups;
- }
-
- private byte[][] convert(String oid) {
- String[] parts = oid.split("\\.");
- BigInteger[] coms = new BigInteger[parts.length - 1];
- for (int i = 1; i < parts.length; ++i) {
- coms[i - 1] = new BigInteger(parts[i]);
- }
- coms[0] = coms[0].add(BigInteger.valueOf(Integer.parseInt(parts[0]) * 40));
-
- byte[][] bytesGroups = new byte[coms.length][];
- for (int i = 0; i < coms.length; ++i) {
- bytesGroups[i] = convert(coms[i]);
- }
-
- return bytesGroups;
- }
-
- private byte[] convert(BigInteger value) {
- int bitLen = value.bitLength();
-
- if (bitLen < 8) {
- return new byte[] {value.byteValue()};
- }
-
- int len = (bitLen + 6) / 7;
- byte[] bytes = new byte[len];
- BigInteger tmpValue = value;
- for (int i = len - 1; i >= 0; i--) {
- bytes[i] = (byte) ((tmpValue.byteValue() & 0x7f) | 0x80);
- tmpValue = tmpValue.shiftRight(7);
- }
- bytes[len - 1] &= 0x7f;
-
- return bytes;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1OctetString.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1OctetString.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1OctetString.java
deleted file mode 100644
index e9de89a..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1OctetString.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/**
- * 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 org.apache.kerby.asn1.parse.Asn1Item;
-import org.apache.kerby.asn1.parse.Asn1ParseResult;
-
-import java.io.IOException;
-
-public class Asn1OctetString extends Asn1Simple<byte[]> {
- public Asn1OctetString() {
- this(null);
- }
-
- public Asn1OctetString(byte[] value) {
- super(UniversalTag.OCTET_STRING, value);
- }
-
- @Override
- protected byte[] encodeBody() {
- return getValue();
- }
-
- @Override
- protected int encodingBodyLength() {
- if (getValue() != null) {
- return getValue().length;
- }
- return 0;
- }
-
- @Override
- protected void decodeBody(Asn1ParseResult parseResult) throws IOException {
- Asn1Item item = (Asn1Item) parseResult;
- setValue(item.readBodyBytes());
- }
-
- @Override
- public String toString() {
- String typeStr = tag().typeStr() + " ["
- + "tag=" + tag()
- + ", len=" + getHeaderLength() + "+" + getBodyLength()
- + "] ";
-
- byte[] valueBytes = getValue();
- String valueStr = "<null>";
- if (valueBytes != null) {
- valueStr = "<" + valueBytes.length + " octets>";
- }
-
- return typeStr + valueStr;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1PrintableString.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1PrintableString.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1PrintableString.java
deleted file mode 100644
index 0401757..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1PrintableString.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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;
-
-public class Asn1PrintableString extends Asn1String {
- public Asn1PrintableString() {
- this(null);
- }
-
- public Asn1PrintableString(String value) {
- super(UniversalTag.PRINTABLE_STRING, value);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Sequence.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Sequence.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Sequence.java
deleted file mode 100644
index c5a7dfc..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Sequence.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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;
-
-public class Asn1Sequence extends Asn1Collection {
- public Asn1Sequence() {
- super(UniversalTag.SEQUENCE);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SequenceOf.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SequenceOf.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SequenceOf.java
deleted file mode 100644
index 074a8b7..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SequenceOf.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * 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;
-
-public class Asn1SequenceOf<T extends Asn1Type> extends Asn1CollectionOf<T> {
- public Asn1SequenceOf() {
- super(UniversalTag.SEQUENCE_OF);
- }
-
- public boolean isEmpty() {
- return getValue() == null || getElements().size() == 0;
- }
-
- public void add(T element) {
- addElement(element);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SequenceType.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SequenceType.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SequenceType.java
deleted file mode 100644
index 85d2763..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SequenceType.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.Asn1FieldInfo;
-import org.apache.kerby.asn1.UniversalTag;
-
-/**
- * For sequence type that consists of tagged fields
- */
-public class Asn1SequenceType extends Asn1CollectionType {
-
- public Asn1SequenceType(Asn1FieldInfo[] tags) {
- super(UniversalTag.SEQUENCE, tags);
- }
-
- @Override
- protected Asn1Collection createCollection() {
- return new Asn1Sequence();
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Set.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Set.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Set.java
deleted file mode 100644
index c2cded4..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Set.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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;
-
-public class Asn1Set extends Asn1Collection {
- public Asn1Set() {
- super(UniversalTag.SET);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SetOf.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SetOf.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SetOf.java
deleted file mode 100644
index a351eaf..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SetOf.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/**
- * 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;
-
-public class Asn1SetOf<T extends Asn1Type> extends Asn1CollectionOf<T> {
- public Asn1SetOf() {
- super(UniversalTag.SET_OF);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SetType.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SetType.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SetType.java
deleted file mode 100644
index 63b64cd..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1SetType.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.Asn1FieldInfo;
-import org.apache.kerby.asn1.UniversalTag;
-
-/**
- * For set type that consists of tagged fields
- */
-public class Asn1SetType extends Asn1CollectionType {
-
- public Asn1SetType(Asn1FieldInfo[] tags) {
- super(UniversalTag.SET, tags);
- }
-
- @Override
- protected Asn1Collection createCollection() {
- return new Asn1Set();
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
deleted file mode 100644
index 2980086..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Simple.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/**
- * 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.Tag;
-import org.apache.kerby.asn1.UniversalTag;
-import org.apache.kerby.asn1.parse.Asn1Item;
-import org.apache.kerby.asn1.parse.Asn1ParseResult;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-/**
- * ASN1 simple type, of single value other than complex type of multiple values.
- */
-public abstract class Asn1Simple<T> extends AbstractAsn1Type<T> {
- private byte[] bytes;
-
- /**
- * Default constructor, generally for decoding as a value container
- * @param tagNo The tag number
- */
- public Asn1Simple(UniversalTag tagNo) {
- this(tagNo, null);
- }
-
- /**
- * Constructor with a value, generally for encoding of the value
- * @param universalTag The tag number
- * @param value The value
- */
- public Asn1Simple(UniversalTag universalTag, T value) {
- super(universalTag, value);
- usePrimitive(true);
- }
-
- @Override
- public boolean isDefinitiveLength() {
- return true; // TO-BE-FIXED: some primitive types may not.
- }
-
- protected byte[] getBytes() {
- return bytes;
- }
-
- protected void setBytes(byte[] bytes) {
- this.bytes = bytes;
- }
-
- protected byte[] encodeBody() {
- if (bytes == null) {
- toBytes();
- }
- return bytes;
- }
-
- @Override
- protected void encodeBody(ByteBuffer buffer) {
- byte[] body = encodeBody();
- if (body != null) {
- buffer.put(body);
- }
- }
-
- @Override
- protected int encodingBodyLength() {
- if (getValue() == null) {
- return 0;
- }
- if (bytes == null) {
- toBytes();
- }
- return bytes.length;
- }
-
- @Override
- protected void decodeBody(Asn1ParseResult parseResult) throws IOException {
- Asn1Item item = (Asn1Item) parseResult;
- byte[] leftBytes = item.readBodyBytes();
- if (leftBytes.length > 0) {
- setBytes(leftBytes);
- toValue();
- }
- }
-
- protected void toValue() throws IOException { }
-
- protected void toBytes() { }
-
- public static boolean isSimple(Tag tag) {
- return isSimple(tag.universalTag());
- }
-
- public static boolean isSimple(int tag) {
- return isSimple(new Tag(tag));
- }
-
- public static boolean isSimple(UniversalTag tagNo) {
- switch (tagNo) {
- case BIT_STRING:
- case BMP_STRING:
- case BOOLEAN:
- case ENUMERATED:
- case GENERALIZED_TIME:
- case GENERAL_STRING:
- case IA5_STRING:
- case INTEGER:
- case NULL:
- case NUMERIC_STRING:
- case OBJECT_IDENTIFIER:
- case OCTET_STRING:
- case PRINTABLE_STRING:
- case T61_STRING:
- case UNIVERSAL_STRING:
- case UTC_TIME:
- case UTF8_STRING:
- case VISIBLE_STRING:
- return true;
- default:
- return false;
- }
- }
-
- /**
- * Create a simple ASN1 object given tagNo, using the default constructor
- * with no value provided
- * @param tagNo The tag number
- * @return A simple ASN1 object
- */
- public static Asn1Simple<?> createSimple(int tagNo) {
- if (!isSimple(tagNo)) {
- throw new IllegalArgumentException("Not simple type, tag: " + tagNo);
- }
- return createSimple(UniversalTag.fromValue(tagNo));
- }
-
- /**
- * Create a simple ASN1 object given tagNo, using the default constructor
- * with no value provided
- * @param tagNo The tag number
- * @return The simple ASN1 object
- */
- public static Asn1Simple<?> createSimple(UniversalTag tagNo) {
- if (!isSimple(tagNo)) {
- throw new IllegalArgumentException("Not simple type, tag: " + tagNo);
- }
-
- switch (tagNo) {
- case BIT_STRING:
- return new Asn1BitString();
- case BMP_STRING:
- return new Asn1BmpString();
- case BOOLEAN:
- return new Asn1Boolean();
- case ENUMERATED:
- return null;
- case GENERALIZED_TIME:
- return new Asn1GeneralizedTime();
- case GENERAL_STRING:
- return new Asn1GeneralString();
- case IA5_STRING:
- return new Asn1IA5String();
- case INTEGER:
- return new Asn1Integer();
- case NULL:
- return Asn1Null.INSTANCE;
- case NUMERIC_STRING:
- return new Asn1NumericsString();
- case OBJECT_IDENTIFIER:
- return new Asn1ObjectIdentifier();
- case OCTET_STRING:
- return new Asn1OctetString();
- case PRINTABLE_STRING:
- return new Asn1PrintableString();
- case T61_STRING:
- return new Asn1T61String();
- case UNIVERSAL_STRING:
- return new Asn1UniversalString();
- case UTC_TIME:
- return new Asn1UtcTime();
- case UTF8_STRING:
- return new Asn1Utf8String();
- case VISIBLE_STRING:
- return new Asn1VisibleString();
- default:
- throw new IllegalArgumentException(
- "Unexpected tag " + tagNo.getValue());
- }
- }
-
- @Override
- public String toString() {
- String typeStr = simpleInfo();
- T theValue = getValue();
- String valueStr = (theValue != null ? String.valueOf(theValue) : "null");
- return typeStr + valueStr;
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Specific.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Specific.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Specific.java
deleted file mode 100644
index 423e67e..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Specific.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/**
- * 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.Tag;
-import org.apache.kerby.asn1.parse.Asn1ParseResult;
-
-import java.io.IOException;
-
-/**
- * Application or context specific object mainly for using implicit encoding.
- */
-public class Asn1Specific extends AbstractAsn1Type<byte[]> {
-
- public Asn1Specific(Tag tag, byte[] value) {
- super(tag, value);
- }
-
- public Asn1Specific(Tag tag) {
- super(tag);
- }
-
- @Override
- protected int encodingBodyLength() {
- if (getValue() != null) {
- return getValue().length;
- }
- return 0;
- }
-
- @Override
- protected void decodeBody(Asn1ParseResult parseResult) throws IOException {
- setValue(parseResult.readBodyBytes());
- }
-
- @Override
- public String toString() {
- return tag().typeStr() + " <" + getValue().length + " bytes>";
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1String.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1String.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1String.java
deleted file mode 100644
index 355dd8c..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1String.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/**
- * 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.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.List;
-
-public abstract class Asn1String extends Asn1Simple<String> {
- public Asn1String(UniversalTag universalTag) {
- super(universalTag, null);
- }
-
- public Asn1String(UniversalTag tagNo, String value) {
- super(tagNo, value);
- }
-
- @Override
- protected void toBytes() {
- if (getValue() != null) {
- byte[] bytes = getValue().getBytes(StandardCharsets.US_ASCII);
- setBytes(bytes);
- }
- }
-
- @Override
- protected int encodingBodyLength() {
- if (getValue() != null) {
- return getValue().length();
- }
- return 0;
- }
-
- protected void toValue() throws IOException {
- byte[] bytes = getBytes();
- setValue(new String(bytes, StandardCharsets.US_ASCII));
- }
-
- public static String fromUTF8ByteArray(byte[] bytes) {
- int i = 0;
- int length = 0;
-
- while (i < bytes.length) {
- length++;
- if ((bytes[i] & 0xf0) == 0xf0) {
- // surrogate pair
- length++;
- i += 4;
- } else if ((bytes[i] & 0xe0) == 0xe0) {
- i += 3;
- } else if ((bytes[i] & 0xc0) == 0xc0) {
- i += 2;
- } else {
- i += 1;
- }
- }
-
- char[] cs = new char[length];
- i = 0;
- length = 0;
-
- while (i < bytes.length) {
- char ch;
-
- if ((bytes[i] & 0xf0) == 0xf0) {
- int codePoint = ((bytes[i] & 0x03) << 18) | ((bytes[i + 1] & 0x3F) << 12)
- | ((bytes[i + 2] & 0x3F) << 6) | (bytes[i + 3] & 0x3F);
- int u = codePoint - 0x10000;
- char w1 = (char) (0xD800 | (u >> 10));
- char w2 = (char) (0xDC00 | (u & 0x3FF));
- cs[length++] = w1;
- ch = w2;
- i += 4;
- } else if ((bytes[i] & 0xe0) == 0xe0) {
- ch = (char) (((bytes[i] & 0x0f) << 12)
- | ((bytes[i + 1] & 0x3f) << 6) | (bytes[i + 2] & 0x3f));
- i += 3;
- } else if ((bytes[i] & 0xd0) == 0xd0) {
- ch = (char) (((bytes[i] & 0x1f) << 6) | (bytes[i + 1] & 0x3f));
- i += 2;
- } else if ((bytes[i] & 0xc0) == 0xc0) {
- ch = (char) (((bytes[i] & 0x1f) << 6) | (bytes[i + 1] & 0x3f));
- i += 2;
- } else {
- ch = (char) (bytes[i] & 0xff);
- i += 1;
- }
-
- cs[length++] = ch;
- }
-
- return new String(cs);
- }
-
- public static byte[] toUTF8ByteArray(String string) {
- return toUTF8ByteArray(string.toCharArray());
- }
-
- public static byte[] toUTF8ByteArray(char[] string) {
- ByteArrayOutputStream bOut = new ByteArrayOutputStream();
-
- try {
- toUTF8ByteArray(string, bOut);
- } catch (IOException e) {
- throw new IllegalStateException("cannot encode string to byte array!");
- }
-
- return bOut.toByteArray();
- }
-
- public static void toUTF8ByteArray(char[] string, OutputStream sOut) throws IOException {
- char[] c = string;
- int i = 0;
-
- while (i < c.length) {
- char ch = c[i];
-
- if (ch < 0x0080) {
- sOut.write(ch);
- } else if (ch < 0x0800) {
- sOut.write(0xc0 | (ch >> 6));
- sOut.write(0x80 | (ch & 0x3f));
- } else if (ch >= 0xD800 && ch <= 0xDFFF) {
- // in error - can only happen, if the Java String class has a
- // bug.
- if (i + 1 >= c.length) {
- throw new IllegalStateException("invalid UTF-16 codepoint");
- }
- char w1 = ch;
- ch = c[++i];
- char w2 = ch;
- // in error - can only happen, if the Java String class has a
- // bug.
- if (w1 > 0xDBFF) {
- throw new IllegalStateException("invalid UTF-16 codepoint");
- }
- int codePoint = ((w1 & 0x03FF) << 10) | (w2 & 0x03FF) + 0x10000;
- sOut.write(0xf0 | (codePoint >> 18));
- sOut.write(0x80 | ((codePoint >> 12) & 0x3F));
- sOut.write(0x80 | ((codePoint >> 6) & 0x3F));
- sOut.write(0x80 | (codePoint & 0x3F));
- } else {
- sOut.write(0xe0 | (ch >> 12));
- sOut.write(0x80 | ((ch >> 6) & 0x3F));
- sOut.write(0x80 | (ch & 0x3F));
- }
-
- i++;
- }
- }
-
- /**
- * A locale independent version of toUpperCase.
- *
- * @param string input to be converted
- * @return a US Ascii uppercase version
- */
- public static String toUpperCase(String string) {
- boolean changed = false;
- char[] chars = string.toCharArray();
-
- for (int i = 0; i != chars.length; i++) {
- char ch = chars[i];
- if ('a' <= ch && 'z' >= ch) {
- changed = true;
- chars[i] = (char) (ch - 'a' + 'A');
- }
- }
-
- if (changed) {
- return new String(chars);
- }
-
- return string;
- }
-
- /**
- * A locale independent version of toLowerCase.
- *
- * @param string input to be converted
- * @return a US ASCII lowercase version
- */
- public static String toLowerCase(String string) {
- boolean changed = false;
- char[] chars = string.toCharArray();
-
- for (int i = 0; i != chars.length; i++) {
- char ch = chars[i];
- if ('A' <= ch && 'Z' >= ch) {
- changed = true;
- chars[i] = (char) (ch - 'A' + 'a');
- }
- }
-
- if (changed) {
- return new String(chars);
- }
-
- return string;
- }
-
- public static byte[] toByteArray(char[] chars) {
- byte[] bytes = new byte[chars.length];
-
- for (int i = 0; i != bytes.length; i++) {
- bytes[i] = (byte) chars[i];
- }
-
- return bytes;
- }
-
- public static byte[] toByteArray(String string) {
- byte[] bytes = new byte[string.length()];
-
- for (int i = 0; i != bytes.length; i++) {
- char ch = string.charAt(i);
-
- bytes[i] = (byte) ch;
- }
-
- return bytes;
- }
-
- /**
- * Convert an array of 8 bit characters into a string.
- *
- * @param bytes 8 bit characters.
- * @return resulting String.
- */
- public static String fromByteArray(byte[] bytes) {
- return new String(asCharArray(bytes));
- }
-
- /**
- * Do a simple conversion of an array of 8 bit characters into a string.
- *
- * @param bytes 8 bit characters.
- * @return resulting String.
- */
- public static char[] asCharArray(byte[] bytes) {
- char[] chars = new char[bytes.length];
-
- for (int i = 0; i != chars.length; i++) {
- chars[i] = (char) (bytes[i] & 0xff);
- }
-
- return chars;
- }
-
- public static String[] split(String input, char delimiter) {
- List<String> v = new ArrayList<String>();
- boolean moreTokens = true;
- String subString;
-
- while (moreTokens) {
- int tokenLocation = input.indexOf(delimiter);
- if (tokenLocation > 0) {
- subString = input.substring(0, tokenLocation);
- v.add(subString);
- input = input.substring(tokenLocation + 1);
- } else {
- moreTokens = false;
- v.add(input);
- }
- }
-
- return v.toArray(new String[v.size()]);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1T61String.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1T61String.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1T61String.java
deleted file mode 100644
index d00eb11..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1T61String.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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;
-
-public class Asn1T61String extends Asn1String {
- public Asn1T61String() {
- this(null);
- }
-
- public Asn1T61String(String value) {
- super(UniversalTag.T61_STRING, value);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1T61Utf8String.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1T61Utf8String.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1T61Utf8String.java
deleted file mode 100644
index 9f75aee..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1T61Utf8String.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * 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.nio.charset.StandardCharsets;
-
-public class Asn1T61Utf8String extends Asn1String {
- public Asn1T61Utf8String() {
- this(null);
- }
-
- public Asn1T61Utf8String(String value) {
- super(UniversalTag.T61_STRING, value);
- }
-
- protected void toBytes() {
- setBytes(getValue().getBytes(StandardCharsets.UTF_8));
- }
-
- protected void toValue() {
- setValue(new String(getBytes(), StandardCharsets.UTF_8));
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java
deleted file mode 100644
index 98eefa2..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Tagging.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/**
- * 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.Asn1Dumpable;
-import org.apache.kerby.asn1.Asn1Dumper;
-import org.apache.kerby.asn1.Tag;
-import org.apache.kerby.asn1.parse.Asn1Container;
-import org.apache.kerby.asn1.parse.Asn1ParseResult;
-
-import java.io.IOException;
-import java.lang.reflect.ParameterizedType;
-import java.nio.ByteBuffer;
-
-/**
- * For tagging any Asn1Type with a tagNo
- */
-public class Asn1Tagging<T extends Asn1Type>
- extends AbstractAsn1Type<T> implements Asn1Dumpable {
-
- public Asn1Tagging(int tagNo, T value,
- boolean isAppSpecific, boolean isImplicit) {
- super(makeTag(isAppSpecific, tagNo), value);
- if (value == null) {
- initValue();
- }
- useImplicit(isImplicit);
- }
-
- private static Tag makeTag(boolean isAppSpecific, int tagNo) {
- return isAppSpecific ? Tag.newAppTag(tagNo) : Tag.newCtxTag(tagNo);
- }
-
- @Override
- public void useImplicit(boolean isImplicit) {
- super.useImplicit(isImplicit);
-
- if (!isImplicit) {
- //In effect, explicitly tagged types are structured types consisting
- // of one component, the underlying type.
- usePrimitive(false);
- } else {
- usePrimitive(getValue().isPrimitive());
- }
- }
-
- @Override
- protected int encodingBodyLength() throws IOException {
- Asn1Encodeable value = (Asn1Encodeable) getValue();
- if (isImplicit()) {
- return value.encodingBodyLength();
- } else {
- return value.encodingLength();
- }
- }
-
- @Override
- protected void encodeBody(ByteBuffer buffer) throws IOException {
- Asn1Encodeable value = (Asn1Encodeable) getValue();
- if (isImplicit()) {
- value.encodeBody(buffer);
- } else {
- value.encode(buffer);
- }
- }
-
- @Override
- protected void decodeBody(Asn1ParseResult parseResult) throws IOException {
- Asn1Encodeable value = (Asn1Encodeable) getValue();
- if (isImplicit()) {
- value.decodeBody(parseResult);
- } else {
- Asn1Container container = (Asn1Container) parseResult;
- Asn1ParseResult body = container.getChildren().get(0);
- value.decode(body);
- }
- }
-
- private void initValue() {
- Class<? extends Asn1Type> valueType = (Class<T>) ((ParameterizedType)
- getClass().getGenericSuperclass()).getActualTypeArguments()[0];
- AbstractAsn1Type<?> value;
- try {
- value = (AbstractAsn1Type<?>) valueType.newInstance();
- } catch (Exception e) {
- throw new RuntimeException("Failed to create tagged value", e);
- }
- setValue((T) value);
- }
-
- @Override
- public void dumpWith(Asn1Dumper dumper, int indents) {
- Asn1Type taggedValue = getValue();
- dumper.indent(indents).appendType(getClass());
- dumper.append(simpleInfo()).newLine();
- dumper.dumpType(indents, taggedValue);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingCollection.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingCollection.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingCollection.java
deleted file mode 100644
index 9595866..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingCollection.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/**
- * 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.Asn1Dumpable;
-import org.apache.kerby.asn1.Asn1Dumper;
-import org.apache.kerby.asn1.Asn1FieldInfo;
-import org.apache.kerby.asn1.EnumType;
-import org.apache.kerby.asn1.Tag;
-import org.apache.kerby.asn1.parse.Asn1ParseResult;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-/**
- * For tagging a collection type with tagNo, either application specific or
- * context specific class
- */
-public abstract class Asn1TaggingCollection
- extends AbstractAsn1Type<Asn1CollectionType> implements Asn1Dumpable {
-
- private Asn1Tagging<Asn1CollectionType> tagging;
- private Asn1CollectionType tagged;
-
- public Asn1TaggingCollection(int taggingTagNo, Asn1FieldInfo[] tags,
- boolean isAppSpecific, boolean isImplicit) {
- super(makeTag(isAppSpecific, taggingTagNo));
- this.tagged = createTaggedCollection(tags);
- setValue(tagged);
- this.tagging = new Asn1Tagging<>(taggingTagNo,
- tagged, isAppSpecific, isImplicit);
- }
-
- private static Tag makeTag(boolean isAppSpecific, int tagNo) {
- return isAppSpecific ? Tag.newAppTag(tagNo) : Tag.newCtxTag(tagNo);
- }
-
- protected abstract Asn1CollectionType createTaggedCollection(Asn1FieldInfo[] tags);
-
- @Override
- public Tag tag() {
- return tagging.tag();
- }
-
- @Override
- public int tagNo() {
- return tagging.tagNo();
- }
-
- @Override
- public void usePrimitive(boolean isPrimitive) {
- tagging.usePrimitive(isPrimitive);
- }
-
- @Override
- public boolean isPrimitive() {
- return tagging.isPrimitive();
- }
-
- @Override
- public void useDefinitiveLength(boolean isDefinitiveLength) {
- tagging.useDefinitiveLength(isDefinitiveLength);
- }
-
- @Override
- public boolean isDefinitiveLength() {
- return tagging.isDefinitiveLength();
- }
-
- @Override
- public void useImplicit(boolean isImplicit) {
- tagging.useImplicit(isImplicit);
- }
-
- @Override
- public boolean isImplicit() {
- return tagging.isImplicit();
- }
-
- @Override
- public void useDER() {
- tagging.useDER();
- }
-
- @Override
- public boolean isDER() {
- return tagging.isDER();
- }
-
- @Override
- public void useBER() {
- tagging.useBER();
- }
-
- @Override
- public boolean isBER() {
- return tagging.isBER();
- }
-
- @Override
- public void useCER() {
- tagging.useCER();
- }
-
- @Override
- public boolean isCER() {
- return tagging.isCER();
- }
-
-
- @Override
- protected int encodingBodyLength() throws IOException {
- return tagging.encodingBodyLength();
- }
-
- @Override
- protected void encodeBody(ByteBuffer buffer) throws IOException {
- tagging.encodeBody(buffer);
- }
-
- @Override
- public void decode(ByteBuffer content) throws IOException {
- tagging.decode(content);
- }
-
- @Override
- protected void decodeBody(Asn1ParseResult parseResult) throws IOException {
- tagging.decodeBody(parseResult);
- }
-
- protected <T extends Asn1Type> T getFieldAs(EnumType index, Class<T> t) {
- return tagged.getFieldAs(index, t);
- }
-
- protected void setFieldAs(EnumType index, Asn1Type value) {
- tagged.setFieldAs(index, value);
- }
-
- protected String getFieldAsString(EnumType index) {
- return tagged.getFieldAsString(index);
- }
-
- protected byte[] getFieldAsOctets(EnumType index) {
- return tagged.getFieldAsOctets(index);
- }
-
- protected void setFieldAsOctets(EnumType index, byte[] bytes) {
- tagged.setFieldAsOctets(index, bytes);
- }
-
- protected Integer getFieldAsInteger(EnumType index) {
- return tagged.getFieldAsInteger(index);
- }
-
- protected void setFieldAsInt(EnumType index, int value) {
- tagged.setFieldAsInt(index, value);
- }
-
- protected byte[] getFieldAsOctetBytes(EnumType index) {
- return tagged.getFieldAsOctets(index);
- }
-
- protected void setFieldAsOctetBytes(EnumType index, byte[] value) {
- tagged.setFieldAsOctets(index, value);
- }
-
- @Override
- public void dumpWith(Asn1Dumper dumper, int indents) {
- Asn1Type taggedValue = getValue();
- dumper.indent(indents).appendType(getClass());
- dumper.append(simpleInfo()).newLine();
- dumper.dumpType(indents, taggedValue);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingSequence.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingSequence.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingSequence.java
deleted file mode 100644
index 61128de..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingSequence.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * 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.Asn1FieldInfo;
-
-/**
- * For tagging a sequence type with tagNo, either application specific or context specific class
- */
-public class Asn1TaggingSequence extends Asn1TaggingCollection {
-
- public Asn1TaggingSequence(int taggingTagNo, Asn1FieldInfo[] tags,
- boolean isAppSpecific, boolean isImplicit) {
- super(taggingTagNo, tags, isAppSpecific, isImplicit);
- }
-
- @Override
- protected Asn1CollectionType createTaggedCollection(Asn1FieldInfo[] tags) {
- return new Asn1SequenceType(tags);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingSet.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingSet.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingSet.java
deleted file mode 100644
index e9eb17f..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1TaggingSet.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/**
- * 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.Asn1FieldInfo;
-
-/**
- * For tagging a sequence type with tagNo, either application specific or
- * context specific class
- */
-public class Asn1TaggingSet extends Asn1TaggingCollection {
-
- public Asn1TaggingSet(int taggingTagNo, Asn1FieldInfo[] tags,
- boolean isAppSpecific, boolean isImplicit) {
- super(taggingTagNo, tags, isAppSpecific, isImplicit);
- }
-
- @Override
- protected Asn1CollectionType createTaggedCollection(Asn1FieldInfo[] tags) {
- return new Asn1SetType(tags);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java
deleted file mode 100644
index 6b0fa67..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Type.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/**
- * 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.Tag;
-import org.apache.kerby.asn1.TaggingOption;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-
-/**
- * The ASN1 type interface for all ASN1 types.
- */
-public interface Asn1Type {
- /**
- * Encoding type
- */
- enum EncodingType {
- BER,
- DER,
- CER;
- }
-
- /**
- *
- * @return The tag
- */
- Tag tag();
-
- /**
- * Use primitive or constructed.
- */
- void usePrimitive(boolean isPrimitive);
-
- /**
- * Tells if it is PRIMITIVE or not.
- *
- * @return true if using PRIMITIVE, false otherwise
- */
- boolean isPrimitive();
-
- /**
- * Use definitive length or not.
- * Note definitive length only makes sense when it's constructed.
- */
- void useDefinitiveLength(boolean isDefinitiveLength);
-
- /**
- * Tells if it's definitive length or not.
- * @return The boolean value
- */
- boolean isDefinitiveLength();
-
- /**
- * Use implicit or not.
- */
- void useImplicit(boolean isImplicit);
-
- /**
- * Tells if it's is IMPLICIT or not.
- *
- * @return true if using IMPLICIT, false otherwise
- */
- boolean isImplicit();
-
- /**
- * Set encoding type as DER.
- */
- void useDER();
-
- /**
- * Tells if it's is DER
- *
- * @return true if using DER, false otherwise
- */
- boolean isDER();
-
- /**
- * Set encoding type as BER.
- */
- void useBER();
-
- /**
- * Tells if it's is BER
- *
- * @return true if using BER, false otherwise
- */
- boolean isBER();
-
- /**
- * Set encoding type as CER.
- */
- void useCER();
-
- /**
- * Tells if it's is CER
- *
- * @return true if using CER, false otherwise
- */
- boolean isCER();
-
- /**
- * Get length of encoding bytes by just calculating without real encoding.
- * Generally it's called to prepare for the encoding buffer.
- * @return length of encoding bytes
- */
- int encodingLength() throws IOException;
-
- /**
- * Encode the type, by recursively.
- * @return encoded bytes
- */
- byte[] encode() throws IOException;
-
- /**
- * Encode the type, by recursively, using the provided buffer.
- * @param buffer The byte buffer
- */
- void encode(ByteBuffer buffer) throws IOException;
-
- /**
- * Decode the content bytes into this type.
- * @param content The content bytes
- * @throws IOException e
- */
- void decode(byte[] content) throws IOException;
-
- /**
- * Decode the content bytes into this type.
- * @param content The content bytes
- * @throws IOException e
- */
- void decode(ByteBuffer content) throws IOException;
-
- /**
- * Tag and encode this type using the provided tagging option.
- * @param taggingOption The tagging option
- * @return encoded bytes
- */
- byte[] taggedEncode(TaggingOption taggingOption) throws IOException;
-
- /**
- * Tag and encode this type using the provided tagging option.
- * @param buffer The byte buffer
- * @param taggingOption The tagging option
- */
- void taggedEncode(ByteBuffer buffer, TaggingOption taggingOption) throws IOException;
-
- /**
- * Decode the content bytes into this type as it's tagged with the provided
- * tagging option.
- *
- * See {@link org.apache.kerby.asn1.TaggingOption}
- *
- * @param content The content bytes
- * @param taggingOption The tagging option
- * @throws IOException e
- */
- void taggedDecode(ByteBuffer content, TaggingOption taggingOption) throws IOException;
-
- /**
- * Decode the content bytes into this type as it's tagged with the provided
- * tagging option.
- *
- * See {@link org.apache.kerby.asn1.TaggingOption}
- *
- * @param content The content bytes
- * @param taggingOption The tagging option
- * @throws IOException e
- */
- void taggedDecode(byte[] content, TaggingOption taggingOption) throws IOException;
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1UniversalString.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1UniversalString.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1UniversalString.java
deleted file mode 100644
index 32b08f3..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1UniversalString.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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;
-
-public class Asn1UniversalString extends Asn1String {
- public Asn1UniversalString() {
- this(null);
- }
-
- public Asn1UniversalString(String value) {
- super(UniversalTag.UNIVERSAL_STRING, value);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1UtcTime.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1UtcTime.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1UtcTime.java
deleted file mode 100644
index 2d0e884..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1UtcTime.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/**
- * 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.charset.StandardCharsets;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.SimpleTimeZone;
-
-public class Asn1UtcTime extends Asn1Simple<Date> {
- public Asn1UtcTime() {
- this(null);
- }
-
- public Asn1UtcTime(long time) {
- super(UniversalTag.UTC_TIME, new Date(time * 1000L));
- }
-
- public Asn1UtcTime(Date date) {
- super(UniversalTag.UTC_TIME, date);
- }
-
- protected void toValue() throws IOException {
- String dateStr = new String(getBytes(), StandardCharsets.US_ASCII);
- String fixedDateStr = dateStr;
-
- /*
- * Make sure fixed date str be of the complete pattern 'YYMMDDhhmmss+/-hhmm'
- */
- int strLen = fixedDateStr.length();
- if (strLen == 6) { // YYMMDD
- fixedDateStr += "000000+0000";
- } else if (strLen == 7) { // YYMMDDZ
- fixedDateStr = fixedDateStr.replace("Z", "000000+0000");
- } else if (strLen == 10) { // YYMMDDhhmm
- fixedDateStr += "00+0000";
- } else if (strLen == 11) { // YYMMDDhhmmZ
- fixedDateStr = fixedDateStr.replace("Z", "00+0000");
- } else if (strLen == 12) { // YYMMDDhhmmss
- fixedDateStr += "+0000";
- } else if (strLen == 13) { // YYMMDDhhmmZ
- fixedDateStr = fixedDateStr.replace("Z", "+0000");
- } else if (strLen != 17) {
- throw new IllegalArgumentException("Bad utc time string " + dateStr);
- }
-
- SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmssZ");
- sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
- try {
- setValue(sdf.parse(fixedDateStr));
- } catch (ParseException e) {
- throw new IOException("Failed to parse " + dateStr + " as utc time", e);
- }
- }
-
- @Override
- protected void toBytes() {
- Date date = getValue();
- SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss'Z'");
- sdf.setTimeZone(new SimpleTimeZone(0, "Z"));
-
- String str = sdf.format(date);
- byte[] bytes = str.getBytes(StandardCharsets.US_ASCII);
- setBytes(bytes);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Utf8String.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Utf8String.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Utf8String.java
deleted file mode 100644
index a92f145..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1Utf8String.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * 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.charset.StandardCharsets;
-
-public class Asn1Utf8String extends Asn1String {
- public Asn1Utf8String() {
- this(null);
- }
-
- public Asn1Utf8String(String value) {
- super(UniversalTag.UTF8_STRING, value);
- }
-
- @Override
- protected void toBytes() {
- byte[] bytes = getValue().getBytes(StandardCharsets.UTF_8);
- setBytes(bytes);
- }
-
- protected void toValue() throws IOException {
- byte[] bytes = getBytes();
- setValue(new String(bytes, StandardCharsets.UTF_8));
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1VisibleString.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1VisibleString.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1VisibleString.java
deleted file mode 100644
index 608d2ad..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/type/Asn1VisibleString.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/**
- * 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;
-
-public class Asn1VisibleString extends Asn1String {
- public Asn1VisibleString() {
- this(null);
- }
-
- public Asn1VisibleString(String value) {
- super(UniversalTag.VISIBLE_STRING, value);
- }
-}
http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/9e4dbd6e/kerby-asn1/src/main/java/org/apache/kerby/asn1/util/Asn1Util.java
----------------------------------------------------------------------
diff --git a/kerby-asn1/src/main/java/org/apache/kerby/asn1/util/Asn1Util.java b/kerby-asn1/src/main/java/org/apache/kerby/asn1/util/Asn1Util.java
deleted file mode 100644
index a1f3438..0000000
--- a/kerby-asn1/src/main/java/org/apache/kerby/asn1/util/Asn1Util.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/**
- * 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.util;
-
-import org.apache.kerby.asn1.Tag;
-
-import java.nio.ByteBuffer;
-
-/**
- * The abstract ASN1 object for all the ASN1 types. It provides basic
- * encoding and decoding utilities.
- */
-public final class Asn1Util {
- private Asn1Util() {
-
- }
-
- public static int lengthOfBodyLength(int bodyLength) {
- int length = 1;
-
- if (bodyLength > 127) {
- int payload = bodyLength;
- while (payload != 0) {
- payload >>= 8;
- length++;
- }
- }
-
- return length;
- }
-
- public static int lengthOfTagLength(int tagNo) {
- int length = 1;
-
- if (tagNo >= 31) {
- if (tagNo < 128) {
- length++;
- } else {
- length++;
-
- do {
- tagNo >>= 7;
- length++;
- } while (tagNo > 127);
- }
- }
-
- return length;
- }
-
- public static void encodeTag(ByteBuffer buffer, Tag tag) {
- int flags = tag.tagFlags();
- int tagNo = tag.tagNo();
-
- if (tagNo < 31) {
- buffer.put((byte) (flags | tagNo));
- } else {
- buffer.put((byte) (flags | 0x1f));
- if (tagNo < 128) {
- buffer.put((byte) tagNo);
- } else {
- byte[] tmpBytes = new byte[5]; // 5 * 7 > 32
- int iPut = tmpBytes.length;
-
- tmpBytes[--iPut] = (byte) (tagNo & 0x7f);
- do {
- tagNo >>= 7;
- tmpBytes[--iPut] = (byte) (tagNo & 0x7f | 0x80);
- } while (tagNo > 127);
-
- buffer.put(tmpBytes, iPut, tmpBytes.length - iPut);
- }
- }
- }
-
- public static void encodeLength(ByteBuffer buffer, int bodyLength) {
- if (bodyLength < 128) {
- buffer.put((byte) bodyLength);
- } else {
- int length = 0;
- int payload = bodyLength;
-
- while (payload != 0) {
- payload >>= 8;
- length++;
- }
-
- buffer.put((byte) (length | 0x80));
-
- payload = bodyLength;
- for (int i = length - 1; i >= 0; i--) {
- buffer.put((byte) (payload >> (i * 8)));
- }
- }
- }
-
- public static byte[] readAllLeftBytes(ByteBuffer buffer) {
- byte[] result = new byte[buffer.remaining()];
- buffer.get(result);
- return result;
- }
-}