Raymond Mao | 1c432cb | 2024-10-03 14:50:27 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * PKCS7 helper functions |
| 4 | * |
| 5 | * Copyright (c) 2012 Red Hat, Inc. All Rights Reserved. |
| 6 | * Written by David Howells (dhowells@redhat.com) |
| 7 | */ |
| 8 | #include <linux/kernel.h> |
| 9 | #include <linux/err.h> |
| 10 | #include <crypto/pkcs7_parser.h> |
| 11 | |
| 12 | /** |
| 13 | * pkcs7_get_content_data - Get access to the PKCS#7 content |
| 14 | * @pkcs7: The preparsed PKCS#7 message to access |
| 15 | * @_data: Place to return a pointer to the data |
| 16 | * @_data_len: Place to return the data length |
| 17 | * @_headerlen: Size of ASN.1 header not included in _data |
| 18 | * |
| 19 | * Get access to the data content of the PKCS#7 message. The size of the |
| 20 | * header of the ASN.1 object that contains it is also provided and can be used |
| 21 | * to adjust *_data and *_data_len to get the entire object. |
| 22 | * |
| 23 | * Returns -ENODATA if the data object was missing from the message. |
| 24 | */ |
| 25 | int pkcs7_get_content_data(const struct pkcs7_message *pkcs7, |
| 26 | const void **_data, size_t *_data_len, |
| 27 | size_t *_headerlen) |
| 28 | { |
| 29 | if (!pkcs7->data) |
| 30 | return -ENODATA; |
| 31 | |
| 32 | *_data = pkcs7->data; |
| 33 | *_data_len = pkcs7->data_len; |
| 34 | if (_headerlen) |
| 35 | *_headerlen = pkcs7->data_hdrlen; |
| 36 | return 0; |
| 37 | } |