decode_certs_unittest.cc (1842B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "gtest/gtest.h" 8 9 #include "cert.h" 10 #include "prerror.h" 11 #include "secerr.h" 12 13 class DecodeCertsTest : public ::testing::Test {}; 14 15 TEST_F(DecodeCertsTest, EmptyCertPackage) { 16 // This represents a PKCS#7 ContentInfo with a contentType of 17 // '2.16.840.1.113730.2.5' (Netscape data-type cert-sequence) and a content 18 // consisting of an empty SEQUENCE. This is valid ASN.1, but it contains no 19 // certificates, so CERT_DecodeCertFromPackage should just return a null 20 // pointer. 21 unsigned char emptyCertPackage[] = {0x30, 0x0f, 0x06, 0x09, 0x60, 0x86, 22 0x48, 0x01, 0x86, 0xf8, 0x42, 0x02, 23 0x05, 0xa0, 0x02, 0x30, 0x00}; 24 EXPECT_EQ(nullptr, CERT_DecodeCertFromPackage( 25 reinterpret_cast<char*>(emptyCertPackage), 26 sizeof(emptyCertPackage))); 27 EXPECT_EQ(SEC_ERROR_BAD_DER, PR_GetError()); 28 } 29 30 TEST_F(DecodeCertsTest, EmptySignedData) { 31 // This represents a PKCS#7 ContentInfo of contentType 32 // 1.2.840.113549.1.7.2 (signedData) with missing content. 33 unsigned char emptySignedData[] = {0x30, 0x80, 0x06, 0x09, 0x2a, 0x86, 34 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 35 0x02, 0x00, 0x00, 0x05, 0x00}; 36 37 EXPECT_EQ(nullptr, 38 CERT_DecodeCertFromPackage(reinterpret_cast<char*>(emptySignedData), 39 sizeof(emptySignedData))); 40 EXPECT_EQ(SEC_ERROR_BAD_DER, PR_GetError()); 41 }