Browse Source

[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 years ago
parent
commit
ef50608029
2 changed files with 51 additions and 0 deletions
  1. 35
    0
      src/core/image.c
  2. 16
    0
      src/include/ipxe/image.h

+ 35
- 0
src/core/image.c View File

505
 
505
 
506
 	return 0;
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 View File

17
 
17
 
18
 struct uri;
18
 struct uri;
19
 struct pixel_buffer;
19
 struct pixel_buffer;
20
+struct asn1_cursor;
20
 struct image_type;
21
 struct image_type;
21
 
22
 
22
 /** An executable image */
23
 /** An executable image */
99
 	 * @ret rc		Return status code
100
 	 * @ret rc		Return status code
100
 	 */
101
 	 */
101
 	int ( * pixbuf ) ( struct image *image, struct pixel_buffer **pixbuf );
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
 extern struct image * image_find_selected ( void );
184
 extern struct image * image_find_selected ( void );
171
 extern int image_set_trust ( int require_trusted, int permanent );
185
 extern int image_set_trust ( int require_trusted, int permanent );
172
 extern int image_pixbuf ( struct image *image, struct pixel_buffer **pixbuf );
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
  * Increment reference count on an image
191
  * Increment reference count on an image

Loading…
Cancel
Save