iPXE
asn1_test.c File Reference

ASN.1 self-tests. More...

#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <ipxe/image.h>
#include <ipxe/asn1.h>
#include <ipxe/test.h>
#include "asn1_test.h"

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
void asn1_okx (struct asn1_test *test, const char *file, unsigned int line)
 Report ASN.1 test result.

Detailed Description

ASN.1 self-tests.

Definition in file asn1_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ asn1_okx()

void asn1_okx ( struct asn1_test * test,
const char * file,
unsigned int line )

Report ASN.1 test result.

Parameters
testASN.1 test
fileTest code file
lineTest code line

Definition at line 50 of file asn1_test.c.

50 {
52 struct asn1_cursor *cursor;
53 uint8_t ctx[digest->ctxsize];
55 unsigned int i;
56 size_t offset;
57 int next;
58
59 /* Sanity check */
60 assert ( sizeof ( out ) == digest->digestsize );
61
62 /* Check that image is detected as correct type */
63 okx ( register_image ( test->image ) == 0, file, line );
64 okx ( test->image->type == test->type, file, line );
65
66 /* Check that all ASN.1 objects can be extracted */
67 for ( offset = 0, i = 0 ; i < test->count ; offset = next, i++ ) {
68
69 /* Extract ASN.1 object */
70 next = image_asn1 ( test->image, offset, &cursor );
71 okx ( next >= 0, file, line );
72 okx ( ( ( size_t ) next ) > offset, file, line );
73 if ( next > 0 ) {
74
75 /* Calculate digest of ASN.1 object */
76 digest_init ( digest, ctx );
77 digest_update ( digest, ctx, cursor->data,
78 cursor->len );
79 digest_final ( digest, ctx, out );
80
81 /* Compare against expected digest */
82 okx ( memcmp ( out, test->expected[i].digest,
83 sizeof ( out ) ) == 0, file, line );
84
85 /* Free ASN.1 object */
86 free ( cursor );
87 }
88 }
89
90 /* Check that we have reached the end of the image */
91 okx ( offset == test->image->len, file, line );
92
93 /* Unregister image */
94 unregister_image ( test->image );
95}
struct golan_eq_context ctx
Definition CIB_PRM.h:0
__be32 out[4]
Definition CIB_PRM.h:8
unsigned char uint8_t
Definition stdint.h:10
int image_asn1(struct image *image, size_t offset, struct asn1_cursor **cursor)
Extract ASN.1 object from image.
Definition asn1.c:1028
#define asn1_test_digest_algorithm
Digest algorithm used for ASN.1 tests.
Definition asn1_test.h:12
#define ASN1_TEST_DIGEST_SIZE
Digest size used for ASN.1 tests.
Definition asn1_test.h:15
#define assert(condition)
Assert a condition at run-time.
Definition assert.h:50
uint16_t offset
Offset to command line.
Definition bzimage.h:3
uint32_t next
Next descriptor address.
Definition dwmac.h:11
static int test
Definition epic100.c:73
void unregister_image(struct image *image)
Unregister executable image.
Definition image.c:358
int register_image(struct image *image)
Register executable image.
Definition image.c:315
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition crypto.h:219
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition crypto.h:230
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition crypto.h:224
static void(* free)(struct refcnt *refcnt))
Definition refcnt.h:55
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition string.c:115
An ASN.1 object cursor.
Definition asn1.h:21
const void * data
Start of data.
Definition asn1.h:23
size_t len
Length of data.
Definition asn1.h:25
A message digest algorithm.
Definition crypto.h:19
size_t digestsize
Digest size.
Definition crypto.h:27
size_t ctxsize
Context size.
Definition crypto.h:23
#define okx(success, file, line)
Report test result.
Definition test.h:44

References asn1_test_digest_algorithm, ASN1_TEST_DIGEST_SIZE, assert, ctx, digest_algorithm::ctxsize, asn1_cursor::data, digest_final(), digest_init(), digest_update(), digest_algorithm::digestsize, free, image_asn1(), asn1_cursor::len, memcmp(), next, offset, okx, out, register_image(), test, and unregister_image().