summaryrefslogtreecommitdiff
path: root/smcc/src/main/java/at/gv/egiz/smcc/util/TLVSequence.java
diff options
context:
space:
mode:
authorclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2010-11-10 14:26:19 +0000
committerclemenso <clemenso@8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4>2010-11-10 14:26:19 +0000
commit8a7c17888fd80cf0de70008c31d4679d42dc6489 (patch)
tree93e50f02957dddc3d27628ee69a71fa65d89806a /smcc/src/main/java/at/gv/egiz/smcc/util/TLVSequence.java
parentf52d7c9e8fa0918c511c80c5e298caedb8f39d15 (diff)
downloadmocca-8a7c17888fd80cf0de70008c31d4679d42dc6489.tar.gz
mocca-8a7c17888fd80cf0de70008c31d4679d42dc6489.tar.bz2
mocca-8a7c17888fd80cf0de70008c31d4679d42dc6489.zip
get certificate info from EF.CD
Issue #MOCCA-754 - LIEZertifikat (LIE-Post) Integration git-svn-id: https://joinup.ec.europa.eu/svn/mocca/trunk@828 8a26b1a7-26f0-462f-b9ef-d0e30c41f5a4
Diffstat (limited to 'smcc/src/main/java/at/gv/egiz/smcc/util/TLVSequence.java')
-rw-r--r--smcc/src/main/java/at/gv/egiz/smcc/util/TLVSequence.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/smcc/src/main/java/at/gv/egiz/smcc/util/TLVSequence.java b/smcc/src/main/java/at/gv/egiz/smcc/util/TLVSequence.java
new file mode 100644
index 00000000..2409f212
--- /dev/null
+++ b/smcc/src/main/java/at/gv/egiz/smcc/util/TLVSequence.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2009 Federal Chancellery Austria and
+ * Graz University of Technology
+ *
+ * Licensed 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 at.gv.egiz.smcc.util;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+public class TLVSequence implements Iterable<TLV> {
+
+ private byte[] bytes;
+
+ public TLVSequence(byte[] bytes) {
+ this.bytes = bytes;
+ }
+
+ @Override
+ public Iterator<TLV> iterator() {
+ return new TLVIterator();
+ }
+
+ public byte[] getValue(int tag) {
+ for (TLV tlv : this) {
+ if (tlv.getTag() == tag) {
+ return tlv.getValue();
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ for (TLV tlv : this) {
+ sb.append(tlv).append('\n');
+ }
+ return sb.toString();
+ }
+
+ private class TLVIterator implements Iterator<TLV> {
+
+ private int pos = 0;
+
+ @Override
+ public boolean hasNext() {
+ return (bytes.length - pos > 2);
+ }
+
+ @Override
+ public TLV next() {
+ if (hasNext()) {
+ TLV tlv = new TLV(bytes, pos);
+ pos += tlv.getLength() + 2;
+ return tlv;
+ } else {
+ throw new NoSuchElementException();
+ }
+ }
+
+ @Override
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+}