-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_pk.h
59 lines (50 loc) · 1.64 KB
/
parse_pk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* parse_pk.h -- parse a dnssec-keygen RSA/MD5 private key
*
* Copyright Dean Scarff
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License.
*/
#ifndef PARSE_PK_H
#define PARSE_PK_H
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stddef.h>
#include <stdio.h>
#include <string.h>
/* RSA private key fields. These numbers are guaranteed to be 0-based
* and contiguous, suitable for a lookup table, but have no reliable
* order, except that PKFK_SIZE is the greatest value. */
enum pk_field_key
{
PKFK_MODULUS,
PKFK_PUBLIC_EXPONENT,
PKFK_PRIVATE_EXPONENT,
PKFK_PRIME1,
PKFK_PRIME2,
PKFK_COEFFICIENT,
PKFK_EXPONENT1,
PKFK_EXPONENT2,
PKFK_SIZE
};
/* Callback function signature for parsing. */
typedef void(parse_pk_cbf)(enum pk_field_key, const char *data);
/* Number of octets required to decode the MIME base-64 sequence `str'
* into. */
inline size_t
decode64_length(const char *str)
{
return 3 + strlen(str) * 3 / 4;
}
/* Decode the MIME base-64 sequence `str' (NUL-terminated) to a
* big-endian octet sequence in `dst'. Hope `str' is valid (multiple
* of 4 octets length using padding, no uncoded symbols). `dst' must
* be large enough to hold `decode64_length(str)' octets. Return
* value is the number of decoded octets. */
size_t decode64(char *dst, const char *str);
/* Parse the dnssec-keygen(8) private key file from `fp', calling `cb'
* for each line whose key is recognised. The parameters to `cb' are
* an encoding of the field key and the field data. */
void parse_pk_file(FILE *fp, parse_pk_cbf *cb);
#endif /* !defined(PARSE_PK_H) */