ring/pki/fillins/base64.cc
Bob Beck bc97b7a8e1 Bring in the core of chromium certificate verifier as libpki
Initially this leaves the canonical source in chrome, Additions
and fillins are committed directly, the chrome files are coverted
using the IMPORT script run from the pki directory for the moment.

The intention here is to continue frequent automatic conversion
(and avoid wholesale cosmetic changes in here for now) until
chrome converts to use these files in place of it's versions.
At that point these will become the definiative files, and the
IMPORT script can be tossed out.

A middle step along the way will be to change google3's verify.cc
in third_party/chromium_certificate_verifier to use this instead
of it's own extracted copy.

Status (and what is not done yet) being roughly tracked in README.md

Bug: chromium:1322914

Change-Id: Ibdb5479bc68985fa61ce6b10f98f31f6b3a7cbdf
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/60285
Commit-Queue: Bob Beck <bbe@google.com>
Reviewed-by: Adam Langley <agl@google.com>
2023-06-22 19:34:39 +00:00

49 lines
1.2 KiB
C++

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <openssl/base64.h>
#include "base64.h"
#include <vector>
namespace bssl {
namespace fillins {
bool Base64Encode(const std::string_view &input, std::string *output) {
size_t len;
if (!EVP_EncodedLength(&len, input.size())) {
return false;
}
std::vector<char> encoded(len);
len = EVP_EncodeBlock(reinterpret_cast<uint8_t *>(encoded.data()),
reinterpret_cast<const uint8_t *>(input.data()),
input.size());
if (!len) {
return false;
}
output->assign(encoded.data(), len);
return true;
}
bool Base64Decode(const std::string_view &input, std::string *output) {
size_t len;
if (!EVP_DecodedLength(&len, input.size())) {
return false;
}
std::vector<char> decoded(len);
if (!EVP_DecodeBase64(reinterpret_cast<uint8_t *>(decoded.data()), &len, len,
reinterpret_cast<const uint8_t *>(input.data()),
input.size())) {
return false;
}
output->assign(decoded.data(), len);
return true;
}
} // namespace fillins
} // namespace bssl