Skip to content

Commit

Permalink
Clang-format all of pki.
Browse files Browse the repository at this point in the history
Before making further changes. This pass is without
InsertBraces, will follow up with InsertBraces
for separate review

Bug: 659
Change-Id: Ie311dcd932aec5f98c16573f9326b1918a639adf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64067
Commit-Queue: David Benjamin <davidben@google.com>
Auto-Submit: Bob Beck <bbe@google.com>
Reviewed-by: David Benjamin <davidben@google.com>
  • Loading branch information
Bob Beck authored and Boringssl LUCI CQ committed Nov 21, 2023
1 parent fcd464c commit 5c7a2a0
Show file tree
Hide file tree
Showing 105 changed files with 1,545 additions and 1,780 deletions.
38 changes: 17 additions & 21 deletions pki/asn1_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

#include "asn1_util.h"

#include "parse_certificate.h"
#include <optional>
#include "input.h"
#include "parse_certificate.h"
#include "parser.h"
#include <optional>

namespace bssl::asn1 {

Expand All @@ -17,7 +17,7 @@ namespace {
// sets |*tbs_certificate| ready to parse the Subject. If parsing
// fails, this function returns false and |*tbs_certificate| is left in an
// undefined state.
bool SeekToSubject(der::Input in, der::Parser* tbs_certificate) {
bool SeekToSubject(der::Input in, der::Parser *tbs_certificate) {
// From RFC 5280, section 4.1
// Certificate ::= SEQUENCE {
// tbsCertificate TBSCertificate,
Expand Down Expand Up @@ -71,7 +71,7 @@ bool SeekToSubject(der::Input in, der::Parser* tbs_certificate) {
// sets |*tbs_certificate| ready to parse the SubjectPublicKeyInfo. If parsing
// fails, this function returns false and |*tbs_certificate| is left in an
// undefined state.
bool SeekToSPKI(der::Input in, der::Parser* tbs_certificate) {
bool SeekToSPKI(der::Input in, der::Parser *tbs_certificate) {
return SeekToSubject(in, tbs_certificate) &&
// Skip over Subject.
tbs_certificate->SkipTag(der::kSequence);
Expand All @@ -85,9 +85,8 @@ bool SeekToSPKI(der::Input in, der::Parser* tbs_certificate) {
// ready to parse the Extensions. If extensions are not present, it sets
// |*extensions_present| to false and |*extensions_parser| is left in an
// undefined state.
bool SeekToExtensions(der::Input in,
bool* extensions_present,
der::Parser* extensions_parser) {
bool SeekToExtensions(der::Input in, bool *extensions_present,
der::Parser *extensions_parser) {
bool present;
der::Parser tbs_cert_parser;
if (!SeekToSPKI(in, &tbs_cert_parser))
Expand Down Expand Up @@ -150,10 +149,9 @@ bool SeekToExtensions(der::Input in,
// successful. |*out_extension_present| will be true iff the extension was
// found. In the case where it was found, |*out_extension| will describe the
// extension, or is undefined on parse error or if the extension is missing.
bool ExtractExtensionWithOID(std::string_view cert,
der::Input extension_oid,
bool* out_extension_present,
ParsedExtension* out_extension) {
bool ExtractExtensionWithOID(std::string_view cert, der::Input extension_oid,
bool *out_extension_present,
ParsedExtension *out_extension) {
der::Parser extensions;
bool extensions_present;
if (!SeekToExtensions(der::Input(cert), &extensions_present, &extensions))
Expand Down Expand Up @@ -183,7 +181,7 @@ bool ExtractExtensionWithOID(std::string_view cert,
} // namespace

bool ExtractSubjectFromDERCert(std::string_view cert,
std::string_view* subject_out) {
std::string_view *subject_out) {
der::Parser parser;
if (!SeekToSubject(der::Input(cert), &parser))
return false;
Expand All @@ -194,8 +192,7 @@ bool ExtractSubjectFromDERCert(std::string_view cert,
return true;
}

bool ExtractSPKIFromDERCert(std::string_view cert,
std::string_view* spki_out) {
bool ExtractSPKIFromDERCert(std::string_view cert, std::string_view *spki_out) {
der::Parser parser;
if (!SeekToSPKI(der::Input(cert), &parser))
return false;
Expand All @@ -207,7 +204,7 @@ bool ExtractSPKIFromDERCert(std::string_view cert,
}

bool ExtractSubjectPublicKeyFromSPKI(std::string_view spki,
std::string_view* spk_out) {
std::string_view *spk_out) {
// From RFC 5280, Section 4.1
// SubjectPublicKeyInfo ::= SEQUENCE {
// algorithm AlgorithmIdentifier,
Expand Down Expand Up @@ -256,9 +253,8 @@ bool HasCanSignHttpExchangesDraftExtension(std::string_view cert) {
}

bool ExtractSignatureAlgorithmsFromDERCert(
std::string_view cert,
std::string_view* cert_signature_algorithm_sequence,
std::string_view* tbs_signature_algorithm_sequence) {
std::string_view cert, std::string_view *cert_signature_algorithm_sequence,
std::string_view *tbs_signature_algorithm_sequence) {
// From RFC 5280, section 4.1
// Certificate ::= SEQUENCE {
// tbsCertificate TBSCertificate,
Expand Down Expand Up @@ -309,9 +305,9 @@ bool ExtractSignatureAlgorithmsFromDERCert(

bool ExtractExtensionFromDERCert(std::string_view cert,
std::string_view extension_oid,
bool* out_extension_present,
bool* out_extension_critical,
std::string_view* out_contents) {
bool *out_extension_present,
bool *out_extension_critical,
std::string_view *out_contents) {
*out_extension_present = false;
*out_extension_critical = false;
*out_contents = std::string_view();
Expand Down
32 changes: 15 additions & 17 deletions pki/asn1_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#ifndef BSSL_PKI_ASN1_UTIL_H_
#define BSSL_PKI_ASN1_UTIL_H_

#include "fillins/openssl_util.h"
#include <string_view>
#include "fillins/openssl_util.h"



Expand All @@ -15,29 +15,28 @@ namespace bssl::asn1 {
// ExtractSubjectFromDERCert parses the DER encoded certificate in |cert| and
// extracts the bytes of the X.501 Subject. On successful return, |subject_out|
// is set to contain the Subject, pointing into |cert|.
OPENSSL_EXPORT bool ExtractSubjectFromDERCert(
std::string_view cert,
std::string_view* subject_out);
OPENSSL_EXPORT bool ExtractSubjectFromDERCert(std::string_view cert,
std::string_view *subject_out);

// ExtractSPKIFromDERCert parses the DER encoded certificate in |cert| and
// extracts the bytes of the SubjectPublicKeyInfo. On successful return,
// |spki_out| is set to contain the SPKI, pointing into |cert|.
OPENSSL_EXPORT bool ExtractSPKIFromDERCert(std::string_view cert,
std::string_view* spki_out);
std::string_view *spki_out);

// ExtractSubjectPublicKeyFromSPKI parses the DER encoded SubjectPublicKeyInfo
// in |spki| and extracts the bytes of the SubjectPublicKey. On successful
// return, |spk_out| is set to contain the public key, pointing into |spki|.
OPENSSL_EXPORT bool ExtractSubjectPublicKeyFromSPKI(
std::string_view spki,
std::string_view* spk_out);
OPENSSL_EXPORT bool ExtractSubjectPublicKeyFromSPKI(std::string_view spki,
std::string_view *spk_out);

// HasCanSignHttpExchangesDraftExtension parses the DER encoded certificate
// in |cert| and extracts the canSignHttpExchangesDraft extension
// (https://wicg.github.io/webpackage/draft-yasskin-http-origin-signed-responses.html)
// if present. Returns true if the extension was present, and false if
// the extension was not present or if there was a parsing failure.
OPENSSL_EXPORT bool HasCanSignHttpExchangesDraftExtension(std::string_view cert);
OPENSSL_EXPORT bool HasCanSignHttpExchangesDraftExtension(
std::string_view cert);

// Extracts the two (SEQUENCE) tag-length-values for the signature
// AlgorithmIdentifiers in a DER encoded certificate. Does not use strict
Expand All @@ -52,9 +51,8 @@ OPENSSL_EXPORT bool HasCanSignHttpExchangesDraftExtension(std::string_view cert)
// * |tbs_signature_algorithm_sequence| points at the TLV for
// TBSCertificate.algorithm.
OPENSSL_EXPORT bool ExtractSignatureAlgorithmsFromDERCert(
std::string_view cert,
std::string_view* cert_signature_algorithm_sequence,
std::string_view* tbs_signature_algorithm_sequence);
std::string_view cert, std::string_view *cert_signature_algorithm_sequence,
std::string_view *tbs_signature_algorithm_sequence);

// Extracts the contents of the extension (if any) with OID |extension_oid| from
// the DER-encoded, X.509 certificate in |cert|.
Expand All @@ -65,11 +63,11 @@ OPENSSL_EXPORT bool ExtractSignatureAlgorithmsFromDERCert(
// sets |*out_contents| to the contents of the extension (after unwrapping the
// OCTET STRING).
OPENSSL_EXPORT bool ExtractExtensionFromDERCert(std::string_view cert,
std::string_view extension_oid,
bool* out_extension_present,
bool* out_extension_critical,
std::string_view* out_contents);
std::string_view extension_oid,
bool *out_extension_present,
bool *out_extension_critical,
std::string_view *out_contents);

} // namespace bssl::asn1

#endif // BSSL_PKI_ASN1_UTIL_H_
#endif // BSSL_PKI_ASN1_UTIL_H_
6 changes: 3 additions & 3 deletions pki/cert_error_id.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace bssl {

const char* CertErrorIdToDebugString(CertErrorId id) {
const char *CertErrorIdToDebugString(CertErrorId id) {
// The CertErrorId is simply a pointer for a C-string literal.
return reinterpret_cast<const char*>(id);
return reinterpret_cast<const char *>(id);
}

} // namespace net
} // namespace bssl
6 changes: 3 additions & 3 deletions pki/cert_error_id.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace bssl {
// Equality of CertErrorId can be done using the == operator.
//
// To define new error IDs use the macro DEFINE_CERT_ERROR_ID().
using CertErrorId = const void*;
using CertErrorId = const void *;

// DEFINE_CERT_ERROR_ID() creates a CertErrorId given a non-null C-string
// literal. The string should be a textual name for the error which will appear
Expand All @@ -31,8 +31,8 @@ using CertErrorId = const void*;

// Returns a debug string for a CertErrorId. In practice this returns the
// string literal given to DEFINE_CERT_ERROR_ID(), which is human-readable.
OPENSSL_EXPORT const char* CertErrorIdToDebugString(CertErrorId id);
OPENSSL_EXPORT const char *CertErrorIdToDebugString(CertErrorId id);

} // namespace net
} // namespace bssl

#endif // BSSL_PKI_CERT_ERROR_ID_H_
68 changes: 29 additions & 39 deletions pki/cert_error_params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "fillins/openssl_util.h"
#include "cert_error_params.h"
#include "fillins/openssl_util.h"

#include <memory>

#include "string_util.h"
#include "input.h"
#include <openssl/base.h>
#include "input.h"
#include "string_util.h"

namespace bssl {

Expand All @@ -19,17 +19,15 @@ namespace {
// blobs. It makes a copy of the der::Inputs.
class CertErrorParams2Der : public CertErrorParams {
public:
CertErrorParams2Der(const char* name1,
const der::Input& der1,
const char* name2,
const der::Input& der2)
CertErrorParams2Der(const char *name1, const der::Input &der1,
const char *name2, const der::Input &der2)
: name1_(name1),
der1_(der1.AsString()),
name2_(name2),
der2_(der2.AsString()) {}

CertErrorParams2Der(const CertErrorParams2Der&) = delete;
CertErrorParams2Der& operator=(const CertErrorParams2Der&) = delete;
CertErrorParams2Der(const CertErrorParams2Der &) = delete;
CertErrorParams2Der &operator=(const CertErrorParams2Der &) = delete;

std::string ToDebugString() const override {
std::string result;
Expand All @@ -42,64 +40,62 @@ class CertErrorParams2Der : public CertErrorParams {
}

private:
static void AppendDer(const char* name,
const std::string& der,
std::string* out) {
static void AppendDer(const char *name, const std::string &der,
std::string *out) {
*out += name;
*out +=
": " + bssl::string_util::HexEncode(
reinterpret_cast<const uint8_t*>(der.data()), der.size());
reinterpret_cast<const uint8_t *>(der.data()), der.size());
}

const char* name1_;
const char *name1_;
std::string der1_;

const char* name2_;
const char *name2_;
std::string der2_;
};

// Parameters subclass for describing (and pretty-printing) a single size_t.
class CertErrorParams1SizeT : public CertErrorParams {
public:
CertErrorParams1SizeT(const char* name, size_t value)
CertErrorParams1SizeT(const char *name, size_t value)
: name_(name), value_(value) {}

CertErrorParams1SizeT(const CertErrorParams1SizeT&) = delete;
CertErrorParams1SizeT& operator=(const CertErrorParams1SizeT&) = delete;
CertErrorParams1SizeT(const CertErrorParams1SizeT &) = delete;
CertErrorParams1SizeT &operator=(const CertErrorParams1SizeT &) = delete;

std::string ToDebugString() const override {
return name_ + std::string(": ") +
bssl::string_util::NumberToDecimalString(value_);
}

private:
const char* name_;
const char *name_;
size_t value_;
};

// Parameters subclass for describing (and pretty-printing) two size_t
// values.
class CertErrorParams2SizeT : public CertErrorParams {
public:
CertErrorParams2SizeT(const char* name1,
size_t value1,
const char* name2,
CertErrorParams2SizeT(const char *name1, size_t value1, const char *name2,
size_t value2)
: name1_(name1), value1_(value1), name2_(name2), value2_(value2) {}

CertErrorParams2SizeT(const CertErrorParams2SizeT&) = delete;
CertErrorParams2SizeT& operator=(const CertErrorParams2SizeT&) = delete;
CertErrorParams2SizeT(const CertErrorParams2SizeT &) = delete;
CertErrorParams2SizeT &operator=(const CertErrorParams2SizeT &) = delete;

std::string ToDebugString() const override {
return name1_ + std::string(": ") +
bssl::string_util::NumberToDecimalString(value1_) + "\n" + name2_ +
std::string(": ") + bssl::string_util::NumberToDecimalString(value2_);
std::string(": ") +
bssl::string_util::NumberToDecimalString(value2_);
}

private:
const char* name1_;
const char *name1_;
size_t value1_;
const char* name2_;
const char *name2_;
size_t value2_;
};

Expand All @@ -109,37 +105,31 @@ CertErrorParams::CertErrorParams() = default;
CertErrorParams::~CertErrorParams() = default;

std::unique_ptr<CertErrorParams> CreateCertErrorParams1Der(
const char* name,
const der::Input& der) {
const char *name, const der::Input &der) {
BSSL_CHECK(name);
return std::make_unique<CertErrorParams2Der>(name, der, nullptr,
der::Input());
}

std::unique_ptr<CertErrorParams> CreateCertErrorParams2Der(
const char* name1,
const der::Input& der1,
const char* name2,
const der::Input& der2) {
const char *name1, const der::Input &der1, const char *name2,
const der::Input &der2) {
BSSL_CHECK(name1);
BSSL_CHECK(name2);
return std::make_unique<CertErrorParams2Der>(name1, der1, name2, der2);
}

std::unique_ptr<CertErrorParams> CreateCertErrorParams1SizeT(const char* name,
std::unique_ptr<CertErrorParams> CreateCertErrorParams1SizeT(const char *name,
size_t value) {
BSSL_CHECK(name);
return std::make_unique<CertErrorParams1SizeT>(name, value);
}

OPENSSL_EXPORT std::unique_ptr<CertErrorParams> CreateCertErrorParams2SizeT(
const char* name1,
size_t value1,
const char* name2,
size_t value2) {
const char *name1, size_t value1, const char *name2, size_t value2) {
BSSL_CHECK(name1);
BSSL_CHECK(name2);
return std::make_unique<CertErrorParams2SizeT>(name1, value1, name2, value2);
}

} // namespace net
} // namespace bssl
Loading

0 comments on commit 5c7a2a0

Please sign in to comment.