directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From plusplusjia...@apache.org
Subject directory-kerby git commit: Set the default critical field of Extension be false and add the test.
Date Mon, 14 Dec 2015 03:46:26 GMT
Repository: directory-kerby
Updated Branches:
  refs/heads/pkinit-support ce525ce43 -> 60d61bbe5


Set the default critical field of Extension be false and add the test.


Project: http://git-wip-us.apache.org/repos/asf/directory-kerby/repo
Commit: http://git-wip-us.apache.org/repos/asf/directory-kerby/commit/60d61bbe
Tree: http://git-wip-us.apache.org/repos/asf/directory-kerby/tree/60d61bbe
Diff: http://git-wip-us.apache.org/repos/asf/directory-kerby/diff/60d61bbe

Branch: refs/heads/pkinit-support
Commit: 60d61bbe58ce12fcd50f5786b0c8365ed7f811a7
Parents: ce525ce
Author: plusplusjiajia <jiajia.li@intel.com>
Authored: Mon Dec 14 11:52:49 2015 +0800
Committer: plusplusjiajia <jiajia.li@intel.com>
Committed: Mon Dec 14 11:52:49 2015 +0800

----------------------------------------------------------------------
 .../org/apache/kerby/x509/type/Extension.java   |  5 +-
 .../org/apache/kerby/cms/TestExtension.java     | 54 ++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/60d61bbe/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Extension.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Extension.java b/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Extension.java
index f0f1f3f..a996e1f 100644
--- a/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Extension.java
+++ b/kerby-pkix/src/main/java/org/apache/kerby/x509/type/Extension.java
@@ -58,6 +58,8 @@ public class Extension extends Asn1SequenceType {
         }
     }
 
+    private final boolean critical = false;
+
     static Asn1FieldInfo[] fieldInfos = new Asn1FieldInfo[] {
         new Asn1FieldInfo(EXTN_ID, Asn1ObjectIdentifier.class),
         new Asn1FieldInfo(CRITICAL, Asn1Boolean.class),
@@ -66,6 +68,7 @@ public class Extension extends Asn1SequenceType {
 
     public Extension() {
         super(fieldInfos);
+        setCritical(critical);
     }
 
     public Asn1ObjectIdentifier getExtnId() {
@@ -88,7 +91,7 @@ public class Extension extends Asn1SequenceType {
         return getFieldAsOctets(EXTN_VALUE);
     }
 
-    public void setValue(byte[] value) {
+    public void setExtnValue(byte[] value) {
         setFieldAsOctets(EXTN_VALUE, value);
     }
 }

http://git-wip-us.apache.org/repos/asf/directory-kerby/blob/60d61bbe/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java
----------------------------------------------------------------------
diff --git a/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.java
new file mode 100644
index 0000000..1857e28
--- /dev/null
+++ b/kerby-pkix/src/test/java/org/apache/kerby/cms/TestExtension.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.cms;
+
+import org.apache.kerby.asn1.type.Asn1ObjectIdentifier;
+import org.apache.kerby.x509.type.Extension;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class TestExtension {
+
+    @Test
+    public void testUnsetCritical() throws IOException {
+        Extension extension = new Extension();
+        extension.setExtnId(new Asn1ObjectIdentifier("1.3.6.1.5.2.3.1"));
+        extension.setExtnValue("value".getBytes());
+        byte[] encodedBytes = extension.encode();
+        Extension decodedExtension = new Extension();
+        decodedExtension.decode(encodedBytes);
+        assertThat(decodedExtension.getCritical()).isFalse();
+    }
+
+    @Test
+    public void testSetCritical() throws IOException {
+        Extension extension = new Extension();
+        extension.setCritical(true);
+        extension.setExtnId(new Asn1ObjectIdentifier("1.3.6.1.5.2.3.1"));
+        extension.setExtnValue("value".getBytes());
+        byte[] encodedBytes = extension.encode();
+        Extension decodedExtension = new Extension();
+        decodedExtension.decode(encodedBytes);
+        assertThat(decodedExtension.getCritical()).isTrue();
+    }
+}


Mime
View raw message