Skip to content

Commit

Permalink
Remove the remaining bssl::Main wrappers.
Browse files Browse the repository at this point in the history
We've taken to writing bssl::UniquePtr in full, so it's not buying
us much.

Change-Id: Ia2689366cbb17282c8063608dddcc675518ec0ca
Reviewed-on: https://boringssl-review.googlesource.com/12628
Reviewed-by: David Benjamin <[email protected]>
  • Loading branch information
davidben committed Dec 8, 2016
1 parent 4ba6e19 commit aac1e2d
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 99 deletions.
2 changes: 1 addition & 1 deletion crypto/bio/bio_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ static bool TestASN1() {
return true;
}

int main(void) {
int main() {
CRYPTO_library_init();

#if defined(OPENSSL_WINDOWS)
Expand Down
17 changes: 5 additions & 12 deletions crypto/bytestring/bytestring_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "internal.h"
#include "../internal.h"

namespace bssl {

static bool TestSkip() {
static const uint8_t kData[] = {1, 2, 3};
Expand Down Expand Up @@ -317,7 +316,7 @@ static bool TestCBBBasic() {
}

static bool TestCBBFixed() {
ScopedCBB cbb;
bssl::ScopedCBB cbb;
uint8_t buf[1];
uint8_t *out_buf;
size_t out_size;
Expand Down Expand Up @@ -401,7 +400,7 @@ static bool TestCBBPrefixed() {
}

static bool TestCBBDiscardChild() {
ScopedCBB cbb;
bssl::ScopedCBB cbb;
CBB contents, inner_contents, inner_inner_contents;

if (!CBB_init(cbb.get(), 0) ||
Expand Down Expand Up @@ -804,7 +803,7 @@ static bool TestCBBReserve() {
uint8_t buf[10];
uint8_t *ptr;
size_t len;
ScopedCBB cbb;
bssl::ScopedCBB cbb;
if (!CBB_init_fixed(cbb.get(), buf, sizeof(buf)) ||
// Too large.
CBB_reserve(cbb.get(), &ptr, 11)) {
Expand All @@ -827,7 +826,7 @@ static bool TestCBBReserve() {

static bool TestStickyError() {
// Write an input that exceeds the limit for its length prefix.
ScopedCBB cbb;
bssl::ScopedCBB cbb;
CBB child;
static const uint8_t kZeros[256] = {0};
if (!CBB_init(cbb.get(), 0) ||
Expand Down Expand Up @@ -890,7 +889,7 @@ static bool TestStickyError() {
return true;
}

static int Main() {
int main() {
CRYPTO_library_init();

if (!TestSkip() ||
Expand Down Expand Up @@ -918,9 +917,3 @@ static int Main() {
printf("PASS\n");
return 0;
}

} // namespace bssl

int main() {
return bssl::Main();
}
14 changes: 3 additions & 11 deletions crypto/cipher/aead_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ const EVP_AEAD* EVP_aead_aes_256_gcm_siv(void) {
}
#endif

namespace bssl {

// This program tests an AEAD against a series of test vectors from a file,
// using the FileTest format. As an example, here's a valid test case:
//
Expand All @@ -58,7 +56,7 @@ static bool TestAEAD(FileTest *t, void *arg) {
return false;
}

ScopedEVP_AEAD_CTX ctx;
bssl::ScopedEVP_AEAD_CTX ctx;
if (!EVP_AEAD_CTX_init_with_direction(ctx.get(), aead, key.data(), key.size(),
tag.size(), evp_aead_seal)) {
t->PrintLine("Failed to init AEAD.");
Expand Down Expand Up @@ -208,7 +206,7 @@ static bool TestWithAliasedBuffers(const EVP_AEAD *aead) {
const size_t max_overhead = EVP_AEAD_max_overhead(aead);

std::vector<uint8_t> key(key_len, 'a');
ScopedEVP_AEAD_CTX ctx;
bssl::ScopedEVP_AEAD_CTX ctx;
if (!EVP_AEAD_CTX_init(ctx.get(), aead, key.data(), key_len,
EVP_AEAD_DEFAULT_TAG_LENGTH, nullptr)) {
return false;
Expand Down Expand Up @@ -333,7 +331,7 @@ static const struct KnownAEAD kAEADs[] = {
{ "", NULL, false },
};

static int Main(int argc, char **argv) {
int main(int argc, char **argv) {
CRYPTO_library_init();

if (argc != 3) {
Expand Down Expand Up @@ -371,9 +369,3 @@ static int Main(int argc, char **argv) {

return FileTestMain(TestAEAD, const_cast<EVP_AEAD*>(aead), argv[2]);
}

} // namespace bssl

int main(int argc, char **argv) {
return bssl::Main(argc, argv);
}
11 changes: 2 additions & 9 deletions crypto/cipher/cipher_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@

#include "../test/file_test.h"

namespace bssl {

static const EVP_CIPHER *GetCipher(const std::string &name) {
if (name == "DES-CBC") {
Expand Down Expand Up @@ -127,7 +126,7 @@ static bool TestOperation(FileTest *t,

bool is_aead = EVP_CIPHER_mode(cipher) == EVP_CIPH_GCM_MODE;

ScopedEVP_CIPHER_CTX ctx;
bssl::ScopedEVP_CIPHER_CTX ctx;
if (!EVP_CipherInit_ex(ctx.get(), cipher, nullptr, nullptr, nullptr,
encrypt ? 1 : 0)) {
return false;
Expand Down Expand Up @@ -284,7 +283,7 @@ static bool TestCipher(FileTest *t, void *arg) {
return true;
}

static int Main(int argc, char **argv) {
int main(int argc, char **argv) {
CRYPTO_library_init();

if (argc != 2) {
Expand All @@ -294,9 +293,3 @@ static int Main(int argc, char **argv) {

return FileTestMain(TestCipher, nullptr, argv[1]);
}

} // namespace bssl

int main(int argc, char **argv) {
return bssl::Main(argc, argv);
}
11 changes: 2 additions & 9 deletions crypto/dh/dh_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@
#include <openssl/err.h>
#include <openssl/mem.h>

namespace bssl {

static bool RunBasicTests();
static bool RunRFC5114Tests();
static bool TestBadY();
static bool TestASN1();
static bool TestRFC3526();

static int Main() {
int main() {
CRYPTO_library_init();

if (!RunBasicTests() ||
Expand Down Expand Up @@ -568,7 +567,7 @@ static bool TestASN1() {
return false;
}

ScopedCBB cbb;
bssl::ScopedCBB cbb;
uint8_t *der;
size_t der_len;
if (!CBB_init(cbb.get(), 0) ||
Expand Down Expand Up @@ -661,9 +660,3 @@ static bool TestRFC3526() {

return true;
}

} // namespace bssl

int main() {
return bssl::Main();
}
12 changes: 2 additions & 10 deletions crypto/digest/digest_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
#include "../internal.h"


namespace bssl {

struct MD {
// name is the name of the digest.
const char* name;
Expand Down Expand Up @@ -161,7 +159,7 @@ static bool CompareDigest(const TestVector *test,
}

static int TestDigest(const TestVector *test) {
ScopedEVP_MD_CTX ctx;
bssl::ScopedEVP_MD_CTX ctx;

// Test the input provided.
if (!EVP_DigestInit_ex(ctx.get(), test->md.func(), NULL)) {
Expand Down Expand Up @@ -246,7 +244,7 @@ static int TestGetters() {
return true;
}

static int Main() {
int main() {
CRYPTO_library_init();

for (size_t i = 0; i < OPENSSL_ARRAY_SIZE(kTestVectors); i++) {
Expand All @@ -263,9 +261,3 @@ static int Main() {
printf("PASS\n");
return 0;
}

} // namespace bssl

int main() {
return bssl::Main();
}
15 changes: 4 additions & 11 deletions crypto/evp/evp_extra_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#include <openssl/pkcs8.h>
#include <openssl/rsa.h>

namespace bssl {

// kExampleRSAKeyDER is an RSA private key in ASN.1, DER format. Of course, you
// should never use this key anywhere but in an example.
Expand Down Expand Up @@ -371,7 +370,7 @@ static bssl::UniquePtr<EVP_PKEY> LoadExampleRSAKey() {

static bool TestEVP_DigestSignInit(void) {
bssl::UniquePtr<EVP_PKEY> pkey = LoadExampleRSAKey();
ScopedEVP_MD_CTX md_ctx;
bssl::ScopedEVP_MD_CTX md_ctx;
if (!pkey ||
!EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) ||
!EVP_DigestSignUpdate(md_ctx.get(), kMsg, sizeof(kMsg))) {
Expand Down Expand Up @@ -409,7 +408,7 @@ static bool TestEVP_DigestSignInit(void) {

static bool TestEVP_DigestVerifyInit(void) {
bssl::UniquePtr<EVP_PKEY> pkey = LoadExampleRSAKey();
ScopedEVP_MD_CTX md_ctx;
bssl::ScopedEVP_MD_CTX md_ctx;
if (!pkey ||
!EVP_DigestVerifyInit(md_ctx.get(), NULL, EVP_sha256(), NULL,
pkey.get()) ||
Expand Down Expand Up @@ -591,7 +590,7 @@ static bool TestEVPMarshalEmptyPublicKey(void) {
if (!empty) {
return false;
}
ScopedCBB cbb;
bssl::ScopedCBB cbb;
if (EVP_marshal_public_key(cbb.get(), empty.get())) {
fprintf(stderr, "Marshalled empty public key.\n");
return false;
Expand Down Expand Up @@ -670,7 +669,7 @@ static bool Testd2i_PrivateKey(void) {
return true;
}

static int Main(void) {
int main() {
CRYPTO_library_init();

if (!TestEVP_DigestSignInit()) {
Expand Down Expand Up @@ -718,9 +717,3 @@ static int Main(void) {
printf("PASS\n");
return 0;
}

} // namespace bssl

int main() {
return bssl::Main();
}
11 changes: 2 additions & 9 deletions crypto/evp/evp_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ OPENSSL_MSVC_PRAGMA(warning(pop))

#include "../test/file_test.h"

namespace bssl {

// evp_test dispatches between multiple test types. PrivateKey tests take a key
// name parameter and single block, decode it as a PEM private key, and save it
Expand Down Expand Up @@ -141,7 +140,7 @@ static bool ImportKey(FileTest *t, KeyMap *key_map,
}

// The key must re-encode correctly.
ScopedCBB cbb;
bssl::ScopedCBB cbb;
uint8_t *der;
size_t der_len;
if (!CBB_init(cbb.get(), 0) ||
Expand Down Expand Up @@ -253,7 +252,7 @@ static bool TestEVP(FileTest *t, void *arg) {
return true;
}

static int Main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
CRYPTO_library_init();
if (argc != 2) {
fprintf(stderr, "%s <test file.txt>\n", argv[0]);
Expand All @@ -263,9 +262,3 @@ static int Main(int argc, char *argv[]) {
KeyMap map;
return FileTestMain(TestEVP, &map, argv[1]);
}

} // namespace bssl

int main(int argc, char *argv[]) {
return bssl::Main(argc, argv);
}
11 changes: 2 additions & 9 deletions crypto/hmac/hmac_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@

#include "../test/file_test.h"

namespace bssl {

static const EVP_MD *GetDigest(const std::string &name) {
if (name == "MD5") {
Expand Down Expand Up @@ -117,7 +116,7 @@ static bool TestHMAC(FileTest *t, void *arg) {
}

// Test using HMAC_CTX.
ScopedHMAC_CTX ctx;
bssl::ScopedHMAC_CTX ctx;
if (!HMAC_Init_ex(ctx.get(), key.data(), key.size(), digest, nullptr) ||
!HMAC_Update(ctx.get(), input.data(), input.size()) ||
!HMAC_Final(ctx.get(), mac.get(), &mac_len) ||
Expand Down Expand Up @@ -158,7 +157,7 @@ static bool TestHMAC(FileTest *t, void *arg) {
return true;
}

static int Main(int argc, char *argv[]) {
int main(int argc, char *argv[]) {
CRYPTO_library_init();

if (argc != 2) {
Expand All @@ -168,9 +167,3 @@ static int Main(int argc, char *argv[]) {

return FileTestMain(TestHMAC, nullptr, argv[1]);
}

} // namespace bssl

int main(int argc, char **argv) {
return bssl::Main(argc, argv);
}
11 changes: 2 additions & 9 deletions crypto/x509/x509_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <openssl/pool.h>
#include <openssl/x509.h>

namespace bssl {

static const char kCrossSigningRootPEM[] =
"-----BEGIN CERTIFICATE-----\n"
Expand Down Expand Up @@ -724,7 +723,7 @@ static bool TestSignCtx() {
}

// Test PKCS#1 v1.5.
ScopedEVP_MD_CTX md_ctx;
bssl::ScopedEVP_MD_CTX md_ctx;
if (!EVP_DigestSignInit(md_ctx.get(), NULL, EVP_sha256(), NULL, pkey.get()) ||
!SignatureRoundTrips(md_ctx.get(), pkey.get())) {
fprintf(stderr, "RSA PKCS#1 with SHA-256 failed\n");
Expand Down Expand Up @@ -941,7 +940,7 @@ static bool TestFromBufferReused() {
return true;
}

static int Main() {
int main() {
CRYPTO_library_init();

if (!TestVerify() ||
Expand All @@ -959,9 +958,3 @@ static int Main() {
printf("PASS\n");
return 0;
}

} // namespace bssl

int main() {
return bssl::Main();
}
Loading

0 comments on commit aac1e2d

Please sign in to comment.