clang-format pem.h and convert comments.

Change-Id: Ic35a94eaeff96083ef727907166fb96daed9f8e8
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/43425
Reviewed-by: Adam Langley <agl@google.com>
chromium-5359
David Benjamin 4 years ago committed by Adam Langley
parent a673d02458
commit 5e549fb640
  1. 35
      .clang-format
  2. 179
      include/openssl/pem.h

@ -9,4 +9,37 @@ PointerAlignment: Right
# reconfigure IncludeCategories to match. For now, keep it at Preserve. # reconfigure IncludeCategories to match. For now, keep it at Preserve.
IncludeBlocks: Preserve IncludeBlocks: Preserve
TypenameMacros: ['LHASH_OF', 'STACK_OF'] TypenameMacros: ['LHASH_OF', 'STACK_OF']
StatementMacros:
- "DECLARE_PEM_read"
- "DECLARE_PEM_read_bio"
- "DECLARE_PEM_read_fp"
- "DECLARE_PEM_rw"
- "DECLARE_PEM_rw_cb"
- "DECLARE_PEM_rw_const"
- "DECLARE_PEM_write"
- "DECLARE_PEM_write_bio"
- "DECLARE_PEM_write_bio_const"
- "DECLARE_PEM_write_cb"
- "DECLARE_PEM_write_cb_bio"
- "DECLARE_PEM_write_cb_fp"
- "DECLARE_PEM_write_const"
- "DECLARE_PEM_write_fp"
- "DECLARE_PEM_write_fp_const"
- "IMPLEMENT_PEM_read"
- "IMPLEMENT_PEM_read_bio"
- "IMPLEMENT_PEM_read_fp"
- "IMPLEMENT_PEM_rw"
- "IMPLEMENT_PEM_rw_cb"
- "IMPLEMENT_PEM_rw_const"
- "IMPLEMENT_PEM_write"
- "IMPLEMENT_PEM_write_bio"
- "IMPLEMENT_PEM_write_bio_const"
- "IMPLEMENT_PEM_write_cb"
- "IMPLEMENT_PEM_write_cb_bio"
- "IMPLEMENT_PEM_write_cb_bio_const"
- "IMPLEMENT_PEM_write_cb_const"
- "IMPLEMENT_PEM_write_cb_fp"
- "IMPLEMENT_PEM_write_cb_fp_const"
- "IMPLEMENT_PEM_write_const"
- "IMPLEMENT_PEM_write_fp"
- "IMPLEMENT_PEM_write_fp_const"

@ -62,12 +62,12 @@
#include <openssl/cipher.h> #include <openssl/cipher.h>
#include <openssl/digest.h> #include <openssl/digest.h>
#include <openssl/evp.h> #include <openssl/evp.h>
#include <openssl/stack.h>
#include <openssl/pkcs7.h> #include <openssl/pkcs7.h>
#include <openssl/stack.h>
#include <openssl/x509.h> #include <openssl/x509.h>
/* For compatibility with open-iscsi, which assumes that it can get // For compatibility with open-iscsi, which assumes that it can get
* |OPENSSL_malloc| from pem.h or err.h */ // |OPENSSL_malloc| from pem.h or err.h
#include <openssl/crypto.h> #include <openssl/crypto.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -102,24 +102,23 @@ extern "C" {
#define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY" #define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
#define PEM_STRING_CMS "CMS" #define PEM_STRING_CMS "CMS"
/* enc_type is one off */ // enc_type is one off
#define PEM_TYPE_ENCRYPTED 10 #define PEM_TYPE_ENCRYPTED 10
#define PEM_TYPE_MIC_ONLY 20 #define PEM_TYPE_MIC_ONLY 20
#define PEM_TYPE_MIC_CLEAR 30 #define PEM_TYPE_MIC_CLEAR 30
#define PEM_TYPE_CLEAR 40 #define PEM_TYPE_CLEAR 40
/* These macros make the PEM_read/PEM_write functions easier to maintain and // These macros make the PEM_read/PEM_write functions easier to maintain and
* write. Now they are all implemented with either: // write. Now they are all implemented with either:
* IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...) // IMPLEMENT_PEM_rw(...) or IMPLEMENT_PEM_rw_cb(...)
*/
#ifdef OPENSSL_NO_FP_API #ifdef OPENSSL_NO_FP_API
#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) /**/ #define IMPLEMENT_PEM_read_fp(name, type, str, asn1) //
#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) /**/ #define IMPLEMENT_PEM_write_fp(name, type, str, asn1) //
#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) /**/ #define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) //
#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) /**/ #define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) //
#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) /**/ #define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) //
#else #else
@ -259,18 +258,19 @@ extern "C" {
IMPLEMENT_PEM_read(name, type, str, asn1) \ IMPLEMENT_PEM_read(name, type, str, asn1) \
IMPLEMENT_PEM_write_cb(name, type, str, asn1) IMPLEMENT_PEM_write_cb(name, type, str, asn1)
/* These are the same except they are for the declarations */ // These are the same except they are for the declarations
#if defined(OPENSSL_NO_FP_API) #if defined(OPENSSL_NO_FP_API)
#define DECLARE_PEM_read_fp(name, type) /**/ #define DECLARE_PEM_read_fp(name, type) //
#define DECLARE_PEM_write_fp(name, type) /**/ #define DECLARE_PEM_write_fp(name, type) //
#define DECLARE_PEM_write_cb_fp(name, type) /**/ #define DECLARE_PEM_write_cb_fp(name, type) //
#else #else
#define DECLARE_PEM_read_fp(name, type) \ #define DECLARE_PEM_read_fp(name, type) \
OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u); OPENSSL_EXPORT type *PEM_read_##name(FILE *fp, type **x, \
pem_password_cb *cb, void *u);
#define DECLARE_PEM_write_fp(name, type) \ #define DECLARE_PEM_write_fp(name, type) \
OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x); OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x);
@ -279,13 +279,15 @@ extern "C" {
OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x); OPENSSL_EXPORT int PEM_write_##name(FILE *fp, const type *x);
#define DECLARE_PEM_write_cb_fp(name, type) \ #define DECLARE_PEM_write_cb_fp(name, type) \
OPENSSL_EXPORT int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ OPENSSL_EXPORT int PEM_write_##name( \
unsigned char *kstr, int klen, pem_password_cb *cb, void *u); FILE *fp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \
pem_password_cb *cb, void *u);
#endif #endif
#define DECLARE_PEM_read_bio(name, type) \ #define DECLARE_PEM_read_bio(name, type) \
OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u); OPENSSL_EXPORT type *PEM_read_bio_##name(BIO *bp, type **x, \
pem_password_cb *cb, void *u);
#define DECLARE_PEM_write_bio(name, type) \ #define DECLARE_PEM_write_bio(name, type) \
OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x); OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x);
@ -294,8 +296,9 @@ extern "C" {
OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x); OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, const type *x);
#define DECLARE_PEM_write_cb_bio(name, type) \ #define DECLARE_PEM_write_cb_bio(name, type) \
OPENSSL_EXPORT int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ OPENSSL_EXPORT int PEM_write_bio_##name( \
unsigned char *kstr, int klen, pem_password_cb *cb, void *u); BIO *bp, type *x, const EVP_CIPHER *enc, unsigned char *kstr, int klen, \
pem_password_cb *cb, void *u);
#define DECLARE_PEM_write(name, type) \ #define DECLARE_PEM_write(name, type) \
@ -326,35 +329,61 @@ extern "C" {
DECLARE_PEM_read(name, type) \ DECLARE_PEM_read(name, type) \
DECLARE_PEM_write_cb(name, type) DECLARE_PEM_write_cb(name, type)
/* "userdata": new with OpenSSL 0.9.4 */ // "userdata": new with OpenSSL 0.9.4
typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata); typedef int pem_password_cb(char *buf, int size, int rwflag, void *userdata);
OPENSSL_EXPORT int PEM_get_EVP_CIPHER_INFO(char *header, EVP_CIPHER_INFO *cipher); OPENSSL_EXPORT int PEM_get_EVP_CIPHER_INFO(char *header,
OPENSSL_EXPORT int PEM_do_header (EVP_CIPHER_INFO *cipher, unsigned char *data,long *len, pem_password_cb *callback,void *u); EVP_CIPHER_INFO *cipher);
OPENSSL_EXPORT int PEM_do_header(EVP_CIPHER_INFO *cipher, unsigned char *data,
OPENSSL_EXPORT int PEM_read_bio(BIO *bp, char **name, char **header, unsigned char **data,long *len); long *len, pem_password_cb *callback, void *u);
OPENSSL_EXPORT int PEM_write_bio(BIO *bp,const char *name, const char *hdr, const unsigned char *data, long len);
OPENSSL_EXPORT int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, pem_password_cb *cb, void *u); OPENSSL_EXPORT int PEM_read_bio(BIO *bp, char **name, char **header,
OPENSSL_EXPORT void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, pem_password_cb *cb, void *u); unsigned char **data, long *len);
OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp, void *x, const EVP_CIPHER *enc,unsigned char *kstr,int klen, pem_password_cb *cb, void *u); OPENSSL_EXPORT int PEM_write_bio(BIO *bp, const char *name, const char *hdr,
const unsigned char *data, long len);
OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); OPENSSL_EXPORT int PEM_bytes_read_bio(unsigned char **pdata, long *plen,
OPENSSL_EXPORT int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, unsigned char *kstr, int klen, pem_password_cb *cd, void *u); char **pnm, const char *name, BIO *bp,
pem_password_cb *cb, void *u);
OPENSSL_EXPORT int PEM_read(FILE *fp, char **name, char **header, unsigned char **data,long *len); OPENSSL_EXPORT void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name,
OPENSSL_EXPORT int PEM_write(FILE *fp, const char *name, const char *hdr, const unsigned char *data, long len); BIO *bp, void **x, pem_password_cb *cb,
OPENSSL_EXPORT void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, pem_password_cb *cb, void *u); void *u);
OPENSSL_EXPORT int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, void *x,const EVP_CIPHER *enc,unsigned char *kstr, int klen,pem_password_cb *callback, void *u); OPENSSL_EXPORT int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name,
OPENSSL_EXPORT STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); BIO *bp, void *x, const EVP_CIPHER *enc,
unsigned char *kstr, int klen,
/* PEM_def_callback treats |userdata| as a string and copies it into |buf|, pem_password_cb *cb, void *u);
* assuming its |size| is sufficient. Returns the length of the string, or 0
* if there is not enough room. If either |buf| or |userdata| is NULL, 0 is OPENSSL_EXPORT STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(
* returned. Note that this is different from OpenSSL, which prompts for a BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
* password. */ OPENSSL_EXPORT int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi,
OPENSSL_EXPORT int PEM_def_callback(char *buf, int size, int rwflag, void *userdata); EVP_CIPHER *enc, unsigned char *kstr,
int klen, pem_password_cb *cd,
void *u);
OPENSSL_EXPORT int PEM_read(FILE *fp, char **name, char **header,
unsigned char **data, long *len);
OPENSSL_EXPORT int PEM_write(FILE *fp, const char *name, const char *hdr,
const unsigned char *data, long len);
OPENSSL_EXPORT void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp,
void **x, pem_password_cb *cb, void *u);
OPENSSL_EXPORT int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
void *x, const EVP_CIPHER *enc,
unsigned char *kstr, int klen,
pem_password_cb *callback, void *u);
OPENSSL_EXPORT STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp,
STACK_OF(X509_INFO) *sk,
pem_password_cb *cb,
void *u);
// PEM_def_callback treats |userdata| as a string and copies it into |buf|,
// assuming its |size| is sufficient. Returns the length of the string, or 0
// if there is not enough room. If either |buf| or |userdata| is NULL, 0 is
// returned. Note that this is different from OpenSSL, which prompts for a
// password.
OPENSSL_EXPORT int PEM_def_callback(char *buf, int size, int rwflag,
void *userdata);
OPENSSL_EXPORT void PEM_proc_type(char *buf, int type); OPENSSL_EXPORT void PEM_proc_type(char *buf, int type);
OPENSSL_EXPORT void PEM_dek_info(char *buf, const char *type, int len, char *str); OPENSSL_EXPORT void PEM_dek_info(char *buf, const char *type, int len,
char *str);
DECLARE_PEM_rw(X509, X509) DECLARE_PEM_rw(X509, X509)
@ -397,19 +426,43 @@ DECLARE_PEM_rw_cb(PrivateKey, EVP_PKEY)
DECLARE_PEM_rw(PUBKEY, EVP_PKEY) DECLARE_PEM_rw(PUBKEY, EVP_PKEY)
OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u); OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x,
OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *, const EVP_CIPHER *, char *, int, pem_password_cb *, void *); int nid, char *kstr,
OPENSSL_EXPORT int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u); int klen,
OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u); pem_password_cb *cb,
OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u); void *u);
OPENSSL_EXPORT int PEM_write_bio_PKCS8PrivateKey(BIO *, EVP_PKEY *,
OPENSSL_EXPORT int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc, char *kstr, int klen, pem_password_cb *cb, void *u); const EVP_CIPHER *, char *,
OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u); int, pem_password_cb *,
OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid, char *kstr, int klen, pem_password_cb *cb, void *u); void *);
OPENSSL_EXPORT int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x,
OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u); const EVP_CIPHER *enc, char *kstr,
int klen, pem_password_cb *cb,
OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPHER *enc, char *kstr,int klen, pem_password_cb *cd, void *u); void *u);
OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
char *kstr, int klen,
pem_password_cb *cb, void *u);
OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x,
pem_password_cb *cb, void *u);
OPENSSL_EXPORT int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x,
const EVP_CIPHER *enc, char *kstr,
int klen, pem_password_cb *cb,
void *u);
OPENSSL_EXPORT int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
char *kstr, int klen,
pem_password_cb *cb, void *u);
OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
char *kstr, int klen,
pem_password_cb *cb, void *u);
OPENSSL_EXPORT EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x,
pem_password_cb *cb, void *u);
OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x,
const EVP_CIPHER *enc, char *kstr,
int klen, pem_password_cb *cd,
void *u);
#ifdef __cplusplus #ifdef __cplusplus
@ -432,4 +485,4 @@ OPENSSL_EXPORT int PEM_write_PKCS8PrivateKey(FILE *fp,EVP_PKEY *x,const EVP_CIPH
#define PEM_R_UNSUPPORTED_CIPHER 113 #define PEM_R_UNSUPPORTED_CIPHER 113
#define PEM_R_UNSUPPORTED_ENCRYPTION 114 #define PEM_R_UNSUPPORTED_ENCRYPTION 114
#endif /* OPENSSL_HEADER_PEM_H */ #endif // OPENSSL_HEADER_PEM_H

Loading…
Cancel
Save