| // Copyright 2026 Google LLC | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // https://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // Unless required by applicable law or agreed to in writing, software | |
| // distributed under the License is distributed on an "AS IS" BASIS, | |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| // See the License for the specific language governing permissions and | |
| // limitations under the License. | |
| // | |
| #ifndef THIRD_PARTY_CREDENTIO_CRYPTO_DEFAULT_CMS_CMS_TEST_HELPER_H_ | |
| #define THIRD_PARTY_CREDENTIO_CRYPTO_DEFAULT_CMS_CMS_TEST_HELPER_H_ | |
| #include <string> | |
| #include "crypto/default/cms/cms_parser.h" | |
| #include "openssl/base.h" | |
| #include "openssl/ossl_typ.h" | |
| namespace credentio_cms { | |
| // Read a file from the test data folder and return its contents. | |
| std::string GetRawFileContents(const std::string& filename); | |
| // Read a file from the test data folder, normalizes the line endings and return | |
| // its contents. | |
| std::string GetFileContents(const std::string& filename); | |
| // Quick and dirty functions to extract the CMS object. It only works on the | |
| // test cases. | |
| std::string GetCms(const std::string& message); | |
| // Extract the first Mime part. Only suitable for tests. | |
| // Returns the first mime part on success or check fails on failure. | |
| std::string GetFirstMimePart(const std::string& contents); | |
| // Convert a byte string representing an X509 Name object to a single line | |
| // string. | |
| std::string CBSToName(const ByteString& raw_name); | |
| // Convert a PEM string to an X509 certificate. The caller needs to call | |
| // X509_free on the returned certificate. | |
| X509* PemToCertificate(const std::string& pem); | |
| // Convert a PEM string to an EVP_PKEY private key. The caller needs to call | |
| // EVP_PKEY_free on the returned key. | |
| EVP_PKEY* PemToKey(const std::string& pem); | |
| // Get the raw DER encoding of the OID with the given NID. | |
| std::string NidToDerString(int nid); | |
| } // namespace credentio_cms | |
| #endif // THIRD_PARTY_CREDENTIO_CRYPTO_DEFAULT_CMS_CMS_TEST_HELPER_H_ |