Ver código fonte

[image] Add image_asn1() to extract ASN.1 objects from image

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 anos atrás
pai
commit
ef50608029
2 arquivos alterados com 51 adições e 0 exclusões
  1. 35
    0
      src/core/image.c
  2. 16
    0
      src/include/ipxe/image.h

+ 35
- 0
src/core/image.c Ver arquivo

@@ -505,3 +505,38 @@ int image_pixbuf ( struct image *image, struct pixel_buffer **pixbuf ) {
505 505
 
506 506
 	return 0;
507 507
 }
508
+
509
+/**
510
+ * Extract ASN.1 object from image
511
+ *
512
+ * @v image		Image
513
+ * @v offset		Offset within image
514
+ * @v cursor		ASN.1 cursor to fill in
515
+ * @ret next		Offset to next image, or negative error
516
+ *
517
+ * The caller is responsible for eventually calling free() on the
518
+ * allocated ASN.1 cursor.
519
+ */
520
+int image_asn1 ( struct image *image, size_t offset,
521
+		 struct asn1_cursor **cursor ) {
522
+	int next;
523
+	int rc;
524
+
525
+	/* Sanity check */
526
+	assert ( offset <= image->len );
527
+
528
+	/* Check that this image can be used to extract an ASN.1 object */
529
+	if ( ! ( image->type && image->type->asn1 ) )
530
+		return -ENOTSUP;
531
+
532
+	/* Try creating ASN.1 cursor */
533
+	next = image->type->asn1 ( image, offset, cursor );
534
+	if ( next < 0 ) {
535
+		rc = next;
536
+		DBGC ( image, "IMAGE %s could not extract ASN.1 object: %s\n",
537
+		       image->name, strerror ( rc ) );
538
+		return rc;
539
+	}
540
+
541
+	return next;
542
+}

+ 16
- 0
src/include/ipxe/image.h Ver arquivo

@@ -17,6 +17,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
17 17
 
18 18
 struct uri;
19 19
 struct pixel_buffer;
20
+struct asn1_cursor;
20 21
 struct image_type;
21 22
 
22 23
 /** An executable image */
@@ -99,6 +100,19 @@ struct image_type {
99 100
 	 * @ret rc		Return status code
100 101
 	 */
101 102
 	int ( * pixbuf ) ( struct image *image, struct pixel_buffer **pixbuf );
103
+	/**
104
+	 * Extract ASN.1 object from image
105
+	 *
106
+	 * @v image		Image
107
+	 * @v offset		Offset within image
108
+	 * @v cursor		ASN.1 cursor to fill in
109
+	 * @ret next		Offset to next image, or negative error
110
+	 *
111
+	 * The caller is responsible for eventually calling free() on
112
+	 * the allocated ASN.1 cursor.
113
+	 */
114
+	int ( * asn1 ) ( struct image *image, size_t offset,
115
+			 struct asn1_cursor **cursor );
102 116
 };
103 117
 
104 118
 /**
@@ -170,6 +184,8 @@ extern int image_select ( struct image *image );
170 184
 extern struct image * image_find_selected ( void );
171 185
 extern int image_set_trust ( int require_trusted, int permanent );
172 186
 extern int image_pixbuf ( struct image *image, struct pixel_buffer **pixbuf );
187
+extern int image_asn1 ( struct image *image, size_t offset,
188
+			struct asn1_cursor **cursor );
173 189
 
174 190
 /**
175 191
  * Increment reference count on an image

Carregando…
Cancelar
Salvar