forked from mrmekon/libsimplepgp
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimplepgp.h
More file actions
executable file
·139 lines (123 loc) · 4.29 KB
/
simplepgp.h
File metadata and controls
executable file
·139 lines (123 loc) · 4.29 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* simplepgp.h
* libsimplepgp
*
* Created by Trevor Bentley on 11/1/11.
*
* Copyright 2011 Trevor Bentley
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef _PACKET_H
#include <stdio.h>
#include <stdint.h>
typedef struct spgp_packet_header_struct spgp_pkt_header_t;
typedef struct spgp_packet_struct spgp_packet_t;
typedef struct spgp_mpi_struct spgp_mpi_t;
typedef struct spgp_public_packet_struct spgp_public_pkt_t;
typedef struct spgp_secret_packet_struct spgp_secret_pkt_t;
typedef struct spgp_userid_packet_struct spgp_userid_pkt_t;
typedef struct spgp_session_packet_struct spgp_session_pkt_t;
typedef struct spgp_literal_packet_struct spgp_literal_pkt_t;
typedef struct spgp_signature_packet_struct spgp_signature_pkt_t;
/**
* Initialize simplepgp library
*
* This function MUST be called before calling any other functions in the
* simplepgp library. It initializes global variables and data structures
* that are used throughout the library.
*
* @return 0 on success, non-zero on failure
*/
uint8_t spgp_init(void);
/**
* Call when finished with simplepgp library to free resources.
*
* @return 0 on success, non-zero on failure
*/
uint8_t spgp_close(void);
/**
* Break a binary OpenPGP message into decoded packets.
*
* This is the work-horse function of the library. OpenPGP message, which may
* be keys or encrypted data, are passed into this function. It splits them
* into a linked-list of OpenPGP packets, which can further be manipulated
* by other functions within the library.
*
* Encrypted messages will be decrypted automatically using keys found in the
* in-RAM keychain. See spgp_decrypt_all_secret_keys() for how to load
* a secret key into the keychain.
*
* @param message Binary OpenPGP message to analyze
* @param length Length of |message|
* @return Linked list of decoded PGP packets, or NULL on failure
*/
spgp_packet_t *spgp_decode_message(uint8_t *message, uint32_t length);
/**
* Decrypt all secret keys found in |msg| with given passphrase.
*
* Call this function after decoding a message known to contain secret keys.
* This function decrypts the secret keys in the packet chain, and stores the
* decrypted keys internally in the in-RAM keychain.
*
* @param msg Linked list of PGP packets
* @param passphrase String to use as decryption passphrase. No NUL termination.
* @param length Length of passphrase.
* @return 0 for success, non-0 for failure.
*/
uint8_t spgp_decrypt_all_secret_keys(spgp_packet_t *msg,
uint8_t *passphrase, uint32_t length);
/**
* Gets the literal data buffer from a decrypted message
*
* @param Linked-list of packets to search for data
* @param datalen Set to size of returned data (in bytes)
* @param filename Set to buffer containing filename
* @param filenamelen Set to size of filename (in bytes)
* @return Buffer with literal data, or NULL if none available
*/
char *spgp_get_literal_data(spgp_packet_t *msg, uint32_t *datalen,
char **filename, uint32_t *filenamelen);
/**
* Frees all dynamic resources associated with |pkt|.
*
* @param pkt Pointer-to-pointer-to-packet to free.
*/
void spgp_free_packet(spgp_packet_t **pkt);
/**
* Get last error code
*
* @return Value of last error
*/
uint32_t spgp_err(void);
/**
* Return a string describing error code |err|.
*
* @return String describing error code |err|
*/
const char *spgp_err_str(uint32_t err);
/**
* Return true if debugging enabled, false otherwise.
*
* @return 0 if logging disabled, non-zero if logging enabled.
*/
uint8_t spgp_debug_log_enabled(void);
/**
* Enables debug logging to stderr
*
* @param enable 0 if logging should be off, 1 if logging should be on.
*/
void spgp_debug_log_set(uint8_t enable);
#define _PACKET_H
#endif