added x509_create() synthesis function
authorAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 11 Oct 2007 14:39:40 +0000 (14:39 -0000)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Thu, 11 Oct 2007 14:39:40 +0000 (14:39 -0000)
src/libstrongswan/crypto/x509.c
src/libstrongswan/crypto/x509.h

index 646043b..e8f5823 100755 (executable)
@@ -23,6 +23,8 @@
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
+ *
+ * RCSID $Id$
  */
 
 #include <gmp.h>
@@ -1262,10 +1264,10 @@ static void destroy(private_x509_t *this)
        free(this);
 }
 
-/*
- * Described in header.
+/**
+ * Internal generic constructor
  */
-x509_t *x509_create_from_chunk(chunk_t chunk, u_int level)
+static private_x509_t *x509_create_empty(void)
 {
        private_x509_t *this = malloc_thing(private_x509_t);
        
@@ -1315,6 +1317,30 @@ x509_t *x509_create_from_chunk(chunk_t chunk, u_int level)
        this->public.list = (void(*)(x509_t*, FILE *out, bool utc))list;
        this->public.destroy = (void (*) (x509_t*))destroy;
        
+       return this;
+}
+
+/*
+ * Described in header.
+ */
+x509_t *x509_create_(chunk_t serialNumber, identification_t *issuer, identification_t *subject)
+{
+       private_x509_t *this = x509_create_empty();
+
+       this->serialNumber = serialNumber;
+       this->issuer = issuer->clone(issuer);
+       this->subject = subject->clone(subject);
+
+       return &this->public;
+}
+
+/*
+ * Described in header.
+ */
+x509_t *x509_create_from_chunk(chunk_t chunk, u_int level)
+{
+       private_x509_t *this = x509_create_empty();
+
        if (!parse_certificate(chunk, level, this))
        {
                destroy(this);
index c6fe148..ffb90de 100755 (executable)
@@ -23,6 +23,8 @@
  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  * for more details.
+ *
+ * RCSID $Id$
  */
 
 #ifndef X509_H_
@@ -299,17 +301,34 @@ struct x509_t {
 };
 
 /**
- * @brief Read a x509 certificate from a DER encoded blob.
- * 
+ * @brief Create a X.509 certificate from its components
+ *
+ * @param serialNumber chunk containing the serialNumber
+ * @param issuer               issuer distinguished name
+ * @param notBefore            start date of validity
+ * @param notAfter             end date of validity
+ * @param subject              subject distinguished name
+ *
+ * @return                             created x509_t certificate, or NULL if invalid.
+ *
+ * @ingroup crypto
+ */
+x509_t *x509_create(chunk_t serialNumber, identification_t *issuer,
+                                       time_t notBefore, time_t notAfter,
+                                       identification_t *subject);
+
+/**
+ * @brief Read a X.509 certificate from a DER encoded blob.
+ *
  * @param chunk        chunk containing DER encoded data
- * @return                     created x509_t certificate, or NULL if inv\ 1lid.
+ * @return                     created x509_t certificate, or NULL if invalid.
  * 
  * @ingroup crypto
  */
 x509_t *x509_create_from_chunk(chunk_t chunk, u_int level);
 
 /**
- * @brief Read a x509 certificate from a DER encoded file.
+ * @brief Read a X.509 certificate from a DER encoded file.
  * 
  * @param filename     file containing DER encoded data
  * @param label                label describing kind of certificate