Title: [1066] trunk/jopenssl: Implement a bit more of the functionality
Revision
1066
Author
olabini
Date
2008-07-21 14:42:57 -0400 (Mon, 21 Jul 2008)

Log Message

Implement a bit more of the functionality

Modified Paths


Diff

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7Exception.java (1065 => 1066)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7Exception.java	2008-07-21 18:42:55 UTC (rev 1065)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/PKCS7Exception.java	2008-07-21 18:42:57 UTC (rev 1066)
@@ -34,11 +34,17 @@
 public class PKCS7Exception extends RuntimeException {
     private int method;
     private int reason;
+    private String errorData;
 
     public PKCS7Exception(int method, int reason) {
+        this(method, reason, null);
+    }
+
+    public PKCS7Exception(int method, int reason, String errorData) {
         super();
         this.method = method;
         this.reason = reason;
+        this.errorData = errorData;
     }
 
     public int getMethod() {
@@ -48,4 +54,8 @@
     public int getReason() {
         return this.reason;
     }
+
+    public String getErrorData() {
+        return this.errorData;
+    }
 }// PKCS7Exception

Modified: trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java (1065 => 1066)


--- trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java	2008-07-21 18:42:55 UTC (rev 1065)
+++ trunk/jopenssl/src/java/org/jruby/ext/openssl/impl/SMIME.java	2008-07-21 18:42:57 UTC (rev 1066)
@@ -40,6 +40,12 @@
         this.mime = mime;
     }
 
+    /* c: B64_read_PKCS7
+     *
+     */
+    public PKCS7 readBase64PKCS7(BIO bio) {
+    }
+
     /* c: SMIME_read_PKCS7
      *
      */
@@ -59,13 +65,13 @@
         }
 
 
-        return null;
+        
+        if(!"application/x-pkcs7-mime".equals(hdr.getValue()) &&
+           !"application/pkcs7-mime".equals(hdr.getValue())) {
+            throw new PKCS7Exception(PKCS7.F_SMIME_READ_PKCS7, PKCS7.R_INVALID_MIME_TYPE, "type: " + hdr.getValue());
+        }
 
-// 	if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
-// 		sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-// 		PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_NO_CONTENT_TYPE);
-// 		return NULL;
-// 	}
+        return readBase64PKCS7(bio);
 
 // 	/* Handle multipart/signed */
 
@@ -126,23 +132,5 @@
 // 		} else sk_BIO_pop_free(parts, BIO_vfree);
 // 		return p7;
 // 	}
-		
-// 	/* OK, if not multipart/signed try opaque signature */
-
-// 	if (strcmp (hdr->value, "application/x-pkcs7-mime") &&
-// 	    strcmp (hdr->value, "application/pkcs7-mime")) {
-// 		PKCS7err(PKCS7_F_SMIME_READ_PKCS7,PKCS7_R_INVALID_MIME_TYPE);
-// 		ERR_add_error_data(2, "type: ", hdr->value);
-// 		sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-// 		return NULL;
-// 	}
-
-// 	sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
-	
-// 	if(!(p7 = B64_read_PKCS7(bio))) {
-// 		PKCS7err(PKCS7_F_SMIME_READ_PKCS7, PKCS7_R_PKCS7_PARSE_ERROR);
-// 		return NULL;
-// 	}
-// 	return p7;
     }
 }

Modified: trunk/jopenssl/test/test_java_pkcs7.rb (1065 => 1066)


--- trunk/jopenssl/test/test_java_pkcs7.rb	2008-07-21 18:42:55 UTC (rev 1065)
+++ trunk/jopenssl/test/test_java_pkcs7.rb	2008-07-21 18:42:57 UTC (rev 1066)
@@ -149,8 +149,37 @@
 
         headers = ArrayList.new
         mime.expects(:parseHeaders).with(bio).returns(headers)
+        mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", "application/pkcs7-mime"))
+
+        SMIME.new(mime).readPKCS7(bio, nil)
+      end
+
+      def test_read_pkcs7_throws_correct_exception_if_wrong_content_type
+        bio = BIO.new
+        mime = Mime.new
+
+        headers = ArrayList.new
+        mime.expects(:parseHeaders).with(bio).returns(headers)
         mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", "foo"))
 
+        begin
+          SMIME.new(mime).readPKCS7(bio, nil)
+          assert false
+        rescue PKCS7Exception => e
+          assert_equal PKCS7::F_SMIME_READ_PKCS7, e.cause.get_method
+          assert_equal PKCS7::R_INVALID_MIME_TYPE, e.cause.get_reason
+          assert_equal "type: foo", e.cause.error_data
+        end
+      end
+      
+      def test_read_pkcs7_happy_path_without_multipart
+        bio = BIO.new
+        mime = Mime.new
+
+        headers = ArrayList.new
+        mime.expects(:parseHeaders).with(bio).returns(headers)
+        mime.expects(:findHeader).with(headers, "content-type").returns(MimeHeader.new("content-type", "application/pkcs7-mime"))
+
         SMIME.new(mime).readPKCS7(bio, nil)
       end
     end
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to