Add OpenSSLCertUtils functions for DER encoding/decoding.
[folly.git] / folly / ssl / OpenSSLCertUtils.h
index be8fbec9187d930796215513037e6409049f272f..373fde01b37c6e96beb88120cabd7e3ec9b5f5ed 100644 (file)
@@ -19,7 +19,9 @@
 #include <vector>
 
 #include <folly/Optional.h>
+#include <folly/io/IOBuf.h>
 #include <folly/portability/OpenSSL.h>
+#include <folly/ssl/OpenSSLPtrTypes.h>
 
 namespace folly {
 namespace ssl {
@@ -60,6 +62,20 @@ class OpenSSLCertUtils {
    */
   static folly::Optional<std::string> toString(X509& x509);
 
+  /**
+   * Decodes the DER representation of an X509 certificate.
+   *
+   * Throws on error (if a valid certificate can't be decoded).
+   */
+  static X509UniquePtr derDecode(ByteRange);
+
+  /**
+   * DER encodes an X509 certificate.
+   *
+   * Throws on error.
+   */
+  static std::unique_ptr<IOBuf> derEncode(X509&);
+
  private:
   static std::string getDateTimeStr(const ASN1_TIME* time);
 };