compute memory requirement for PEM-encoding correctly
[strongswan.git] / src / libstrongswan / plugins / pem / pem_encoder.c
index 2132016..9c8237e 100644 (file)
@@ -87,12 +87,31 @@ bool pem_encoder_encode(cred_encoding_type_t type, chunk_t *encoding,
                                break;
                        }
                        return FALSE;
+               case CERT_PEM:
+                       if (cred_encoding_args(args, CRED_PART_X509_ASN1_DER,
+                                                                  &asn1, CRED_PART_END))
+                       {       /* PEM encode x509 certificate */
+                               label = "CERTIFICATE";
+                               break;
+                       }
+                       if (cred_encoding_args(args, CRED_PART_X509_CRL_ASN1_DER,
+                                                                  &asn1, CRED_PART_END))
+                       {       /* PEM encode CRL */
+                               label = "X509 CRL";
+                               break;
+                       }
+                       if (cred_encoding_args(args, CRED_PART_PKCS10_ASN1_DER,
+                                                                  &asn1, CRED_PART_END))
+                       {       /* PEM encode PKCS10 certificate reqeuest */
+                               label = "CERTIFICATE REQUEST";
+                               break;
+                       }
                default:
                        return FALSE;
        }
 
        /* compute and allocate maximum size of PEM object */
-       pem_chars = 4*(asn1.len + 2)/3;
+       pem_chars = 4 * ((asn1.len + 2) / 3);
        pem_lines = (asn1.len + BYTES_PER_LINE - 1) / BYTES_PER_LINE;
        *encoding = chunk_alloc(5 + 2*(6 + strlen(label) + 6) + 3 + pem_chars + pem_lines);
        pos = encoding->ptr;