| 6 | // |
| 7 | // https://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 |
| 15 | #include <openssl/bytestring.h> |
| 16 | #include <openssl/err.h> |
| 17 | #include <openssl/evp.h> |
| 18 | #include <openssl/mem.h> |
| 19 |
| 20 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *buf, size_t len) { |
| 21 | CBS cbs; |
| 22 | CBS_init(&cbs, buf, len); |
| 23 | EVP_PKEY *pkey = EVP_parse_public_key(&cbs); |
| 24 | if (pkey == NULL) { |
| 25 | ERR_clear_error(); |
| 26 | return 0; |
| 27 | } |
| 28 |
| 29 | uint8_t *der; |
| 30 | size_t der_len; |
| 31 | CBB cbb; |
| 32 | if (CBB_init(&cbb, 0) && |
| 33 | EVP_marshal_public_key(&cbb, pkey) && |
| 34 | CBB_finish(&cbb, &der, &der_len)) { |
| 35 | OPENSSL_free(der); |
| 36 | } |
| 37 | CBB_cleanup(&cbb); |
| 38 | EVP_PKEY_free(pkey); |
| 39 | ERR_clear_error(); |
| 40 | return 0; |
| 41 | } |
| 42 |