|
@@ -19,25 +19,31 @@
|
19
|
19
|
#include <stdio.h>
|
20
|
20
|
#include <string.h>
|
21
|
21
|
#include <unistd.h>
|
|
22
|
+#include <getopt.h>
|
22
|
23
|
#include <ipxe/command.h>
|
|
24
|
+#include <ipxe/parseopt.h>
|
23
|
25
|
#include <ipxe/image.h>
|
24
|
26
|
#include <ipxe/crypto.h>
|
25
|
|
-
|
26
|
27
|
#include <ipxe/md5.h>
|
27
|
28
|
#include <ipxe/sha1.h>
|
28
|
29
|
|
29
|
|
-/**
|
30
|
|
- * "digest" command syntax message
|
|
30
|
+/** @file
|
|
31
|
+ *
|
|
32
|
+ * Digest commands
|
31
|
33
|
*
|
32
|
|
- * @v argv Argument list
|
33
|
34
|
*/
|
34
|
|
-static void digest_syntax ( char **argv ) {
|
35
|
|
- printf ( "Usage:\n"
|
36
|
|
- " %s <image name>\n"
|
37
|
|
- "\n"
|
38
|
|
- "Calculate the %s of an image\n",
|
39
|
|
- argv[0], argv[0] );
|
40
|
|
-}
|
|
35
|
+
|
|
36
|
+/** "digest" options */
|
|
37
|
+struct digest_options {};
|
|
38
|
+
|
|
39
|
+/** "digest" option list */
|
|
40
|
+static struct option_descriptor digest_opts[] = {};
|
|
41
|
+
|
|
42
|
+/** "digest" command descriptor */
|
|
43
|
+static struct command_descriptor digest_cmd =
|
|
44
|
+ COMMAND_DESC ( struct digest_options, digest_opts, 1, MAX_ARGUMENTS,
|
|
45
|
+ "<image> [<image>...]",
|
|
46
|
+ "Calculate the digest of an image" );
|
41
|
47
|
|
42
|
48
|
/**
|
43
|
49
|
* The "digest" command
|
|
@@ -45,11 +51,11 @@ static void digest_syntax ( char **argv ) {
|
45
|
51
|
* @v argc Argument count
|
46
|
52
|
* @v argv Argument list
|
47
|
53
|
* @v digest Digest algorithm
|
48
|
|
- * @ret rc Exit code
|
|
54
|
+ * @ret rc Return status code
|
49
|
55
|
*/
|
50
|
56
|
static int digest_exec ( int argc, char **argv,
|
51
|
57
|
struct digest_algorithm *digest ) {
|
52
|
|
- const char *image_name;
|
|
58
|
+ struct digest_options opts;
|
53
|
59
|
struct image *image;
|
54
|
60
|
uint8_t digest_ctx[digest->ctxsize];
|
55
|
61
|
uint8_t digest_out[digest->digestsize];
|
|
@@ -59,23 +65,17 @@ static int digest_exec ( int argc, char **argv,
|
59
|
65
|
size_t frag_len;
|
60
|
66
|
int i;
|
61
|
67
|
unsigned j;
|
|
68
|
+ int rc;
|
62
|
69
|
|
63
|
|
- if ( argc < 2 ||
|
64
|
|
- !strcmp ( argv[1], "--help" ) ||
|
65
|
|
- !strcmp ( argv[1], "-h" ) ) {
|
66
|
|
- digest_syntax ( argv );
|
67
|
|
- return 1;
|
68
|
|
- }
|
|
70
|
+ /* Parse options */
|
|
71
|
+ if ( ( rc = parse_options ( argc, argv, &digest_cmd, &opts ) ) != 0 )
|
|
72
|
+ return rc;
|
69
|
73
|
|
70
|
|
- for ( i = 1 ; i < argc ; i++ ) {
|
71
|
|
- image_name = argv[i];
|
|
74
|
+ for ( i = optind ; i < argc ; i++ ) {
|
72
|
75
|
|
73
|
76
|
/* find image */
|
74
|
|
- image = find_image ( image_name );
|
75
|
|
- if ( ! image ) {
|
76
|
|
- printf ( "No such image: %s\n", image_name );
|
|
77
|
+ if ( ( rc = parse_image ( argv[i], &image ) ) != 0 )
|
77
|
78
|
continue;
|
78
|
|
- }
|
79
|
79
|
offset = 0;
|
80
|
80
|
len = image->len;
|
81
|
81
|
|