File: pem.h

package info (click to toggle)
ekeyd 1.1.3-3
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 628 kB
  • ctags: 859
  • sloc: ansic: 5,189; sh: 271; makefile: 199; perl: 148
file content (60 lines) | stat: -rw-r--r-- 1,822 bytes parent folder | download | duplicates (5)
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
/* frames/pem.h
 *
 * PEM64 encoding for framing.
 *
 * Copyright 2009 Simtec Electronics
 *
 * For licence terms refer to the COPYING file.
 */

#ifndef EKEY_FRAMES_PEM_H
#define EKEY_FRAMES_PEM_H

/*
 * PEM64 encoding takes bytes and encodes them into characters.
 * Each (up-to) three byte input produces four characters of output.
 * It is up to the caller to ensure buffers are the right sizes.
 */

/**
 * Encode some bytes in PEM64.
 *
 * @param inbytes The buffer to encode.
 * @param nbytes The number of bytes to encode.
 * @param outtext The buffer to fill.
 * @return The number of characters inserted into the output buffer.
 */
extern int pem64_encode_bytes(const unsigned char *inbytes,
                              int nbytes,
                              char *outtext);

/**
 * Calculate resulting length of encoding bytes in PEM64.
 *
 * @param nbytes The number of bytes to encode.
 * @return The number of characters required to encode the output bytes.
 */
extern int pem64_encode_bytes_length(int nbytes);

/**
 * Decode some text from PEM64.
 *
 * @param intext The buffer text to decode.
 * @param nchars The number of characters in the buffer.
 * @param outbytes The buffer to fill.
 * @return The number of bytes written into outbytes.
 */
extern int pem64_decode_bytes(const char *intext,
                              int nchars,
                              unsigned char *outbytes);

/** Determine how many chars will be needed to encode N bytes */
#define PEM64_CHARS_NEEDED(nbytes) ((((nbytes) + 2) / 3) * 4)

/** Determine how many bytes (may) be needed to decode N chars */
#define PEM64_BYTES_NEEDED(nchars) (((nchars) / 4) * 3)

extern void pem64_encode_12bits(const short value, char *outtext);
extern short pem64_decode_12bits(const char *intext);

#endif /* EKEY_FRAMES_PEM_H */