diff options
author | Michael Brown | 2016-07-28 17:18:23 +0200 |
---|---|---|
committer | Michael Brown | 2016-07-29 02:12:58 +0200 |
commit | eb7188d04b30dcbc47ac1af621b738cc0923ae38 (patch) | |
tree | fda7f01787ea5ef826befac6be1cf7af55659053 /src/tests/asn1_test.h | |
parent | [image] Add image_asn1() to extract ASN.1 objects from image (diff) | |
download | ipxe-eb7188d04b30dcbc47ac1af621b738cc0923ae38.tar.gz ipxe-eb7188d04b30dcbc47ac1af621b738cc0923ae38.tar.xz ipxe-eb7188d04b30dcbc47ac1af621b738cc0923ae38.zip |
[crypto] Add DER image format
Add DER-encoded ASN.1 as an image format. There is no fixed signature
for DER files. We treat an image as DER if it comprises a single
valid SEQUENCE object covering the entire length of the image.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/tests/asn1_test.h')
-rw-r--r-- | src/tests/asn1_test.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/tests/asn1_test.h b/src/tests/asn1_test.h new file mode 100644 index 00000000..c8167ed3 --- /dev/null +++ b/src/tests/asn1_test.h @@ -0,0 +1,73 @@ +#ifndef _ASN1_TEST_H +#define _ASN1_TEST_H + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include <stdint.h> +#include <ipxe/image.h> +#include <ipxe/sha1.h> +#include <ipxe/test.h> + +/** Digest algorithm used for ASN.1 tests */ +#define asn1_test_digest_algorithm sha1_algorithm + +/** Digest size used for ASN.1 tests */ +#define ASN1_TEST_DIGEST_SIZE SHA1_DIGEST_SIZE + +/** An ASN.1 test digest */ +struct asn1_test_digest { + /** Digest value */ + uint8_t digest[ASN1_TEST_DIGEST_SIZE]; +}; + +/** An ASN.1 test */ +struct asn1_test { + /** Image type */ + struct image_type *type; + /** Source image */ + struct image *image; + /** Expected digests of ASN.1 objects */ + struct asn1_test_digest *expected; + /** Number of ASN.1 objects */ + unsigned int count; +}; + +/** + * Define an ASN.1 test + * + * @v _name Test name + * @v _type Test image file type + * @v _file Test image file data + * @v ... Expected ASN.1 object digests + * @ret test ASN.1 test + */ +#define ASN1( _name, _type, _file, ... ) \ + static const char _name ## __file[] = _file; \ + static struct image _name ## __image = { \ + .refcnt = REF_INIT ( ref_no_free ), \ + .name = #_name, \ + .data = ( userptr_t ) ( _name ## __file ), \ + .len = sizeof ( _name ## __file ), \ + }; \ + static struct asn1_test_digest _name ## _expected[] = { \ + __VA_ARGS__ \ + }; \ + static struct asn1_test _name = { \ + .type = _type, \ + .image = & _name ## __image, \ + .expected = _name ## _expected, \ + .count = ( sizeof ( _name ## _expected ) / \ + sizeof ( _name ## _expected[0] ) ), \ + }; + +extern void asn1_okx ( struct asn1_test *test, const char *file, + unsigned int line ); + +/** + * Report ASN.1 test result + * + * @v test ASN.1 test + */ +#define asn1_ok( test ) asn1_okx ( test, __FILE__, __LINE__ ) + +#endif /* _ASN1_TEST_H */ |