iPXE
asn1_test.h
Go to the documentation of this file.
00001 #ifndef _ASN1_TEST_H
00002 #define _ASN1_TEST_H
00003 
00004 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00005 
00006 #include <stdint.h>
00007 #include <ipxe/image.h>
00008 #include <ipxe/sha1.h>
00009 #include <ipxe/test.h>
00010 
00011 /** Digest algorithm used for ASN.1 tests */
00012 #define asn1_test_digest_algorithm sha1_algorithm
00013 
00014 /** Digest size used for ASN.1 tests */
00015 #define ASN1_TEST_DIGEST_SIZE SHA1_DIGEST_SIZE
00016 
00017 /** An ASN.1 test digest */
00018 struct asn1_test_digest {
00019         /** Digest value */
00020         uint8_t digest[ASN1_TEST_DIGEST_SIZE];
00021 };
00022 
00023 /** An ASN.1 test */
00024 struct asn1_test {
00025         /** Image type */
00026         struct image_type *type;
00027         /** Source image */
00028         struct image *image;
00029         /** Expected digests of ASN.1 objects */
00030         struct asn1_test_digest *expected;
00031         /** Number of ASN.1 objects */
00032         unsigned int count;
00033 };
00034 
00035 /**
00036  * Define an ASN.1 test
00037  *
00038  * @v _name             Test name
00039  * @v _type             Test image file type
00040  * @v _file             Test image file data
00041  * @v ...               Expected ASN.1 object digests
00042  * @ret test            ASN.1 test
00043  */
00044 #define ASN1( _name, _type, _file, ... )                                \
00045         static const char _name ## __file[] = _file;                    \
00046         static struct image _name ## __image = {                        \
00047                 .refcnt = REF_INIT ( ref_no_free ),                     \
00048                 .name = #_name,                                         \
00049                 .data = ( userptr_t ) ( _name ## __file ),              \
00050                 .len = sizeof ( _name ## __file ),                      \
00051         };                                                              \
00052         static struct asn1_test_digest _name ## _expected[] = {         \
00053                 __VA_ARGS__                                             \
00054         };                                                              \
00055         static struct asn1_test _name = {                               \
00056                 .type = _type,                                          \
00057                 .image = & _name ## __image,                            \
00058                 .expected = _name ## _expected,                         \
00059                 .count = ( sizeof ( _name ## _expected ) /              \
00060                            sizeof ( _name ## _expected[0] ) ),          \
00061         };
00062 
00063 extern void asn1_okx ( struct asn1_test *test, const char *file,
00064                        unsigned int line );
00065 
00066 /**
00067  * Report ASN.1 test result
00068  *
00069  * @v test              ASN.1 test
00070  */
00071 #define asn1_ok( test ) asn1_okx ( test, __FILE__, __LINE__ )
00072 
00073 #endif /* _ASN1_TEST_H */