Make base64 encoding/decoding part of rpmio public API
[platform/upstream/rpm.git] / rpmio / digest.h
1 #ifndef _RPMDIGEST_H
2 #define _RPMDIGEST_H
3
4 #include <rpm/rpmpgp.h>
5
6 typedef struct pgpDigAlg_s * pgpDigAlg;
7
8 typedef int (*setmpifunc)(pgpDigAlg digp,
9                           int num, const uint8_t *p, const uint8_t *pend);
10 typedef int (*verifyfunc)(pgpDigAlg pgpkey, pgpDigAlg pgpsig,
11                           uint8_t *hash, size_t hashlen, int hash_algo);
12 typedef void (*freefunc)(pgpDigAlg digp);
13
14 struct pgpDigAlg_s {
15     setmpifunc setmpi;
16     verifyfunc verify;
17     freefunc free;
18     int mpis;
19     void *data;                 /*!< algorithm specific private data */
20 };
21
22 /** \ingroup rpmio
23  * Values parsed from OpenPGP signature/pubkey packet(s).
24  */
25 struct pgpDigParams_s {
26     char * userid;
27     uint8_t * hash;
28     uint8_t tag;
29
30     uint8_t version;            /*!< version number. */
31     pgpTime_t time;             /*!< time that the key was created. */
32     uint8_t pubkey_algo;                /*!< public key algorithm. */
33
34     uint8_t hash_algo;
35     uint8_t sigtype;
36     uint8_t hashlen;
37     uint8_t signhash16[2];
38     pgpKeyID_t signid;
39     uint8_t saved;
40 #define PGPDIG_SAVED_TIME       (1 << 0)
41 #define PGPDIG_SAVED_ID         (1 << 1)
42
43     pgpDigAlg alg;
44 };
45
46 pgpDigAlg pgpPubkeyNew(int algo);
47
48 pgpDigAlg pgpSignatureNew(int algo);
49
50 pgpDigAlg pgpDigAlgFree(pgpDigAlg da);
51
52 /** \ingroup rpmpgp
53  * Return no. of bits in a multiprecision integer.
54  * @param p             pointer to multiprecision integer
55  * @return              no. of bits
56  */
57 static inline
58 unsigned int pgpMpiBits(const uint8_t *p)
59 {
60     return ((p[0] << 8) | p[1]);
61 }
62
63 /** \ingroup rpmpgp
64  * Return no. of bytes in a multiprecision integer.
65  * @param p             pointer to multiprecision integer
66  * @return              no. of bytes
67  */
68 static inline
69 size_t pgpMpiLen(const uint8_t *p)
70 {
71     return (2 + ((pgpMpiBits(p)+7)>>3));
72 }
73         
74 #endif /* _RPMDIGEST_H */