summaryrefslogtreecommitdiffstats
path: root/g10/keyid.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>1997-12-01 11:33:23 +0100
committerWerner Koch <wk@gnupg.org>1997-12-01 11:33:23 +0100
commit5c1cca042e6bc0de22c7913f08457c7b8a46e592 (patch)
tree234246f67cf2e7deb79b94e7491fdd7111c1c65e /g10/keyid.c
parentImproved prime number test (diff)
downloadgnupg2-5c1cca042e6bc0de22c7913f08457c7b8a46e592.tar.xz
gnupg2-5c1cca042e6bc0de22c7913f08457c7b8a46e592.zip
List and check sigs works
Diffstat (limited to 'g10/keyid.c')
-rw-r--r--g10/keyid.c99
1 files changed, 92 insertions, 7 deletions
diff --git a/g10/keyid.c b/g10/keyid.c
index 0e2dad93b..7453754a2 100644
--- a/g10/keyid.c
+++ b/g10/keyid.c
@@ -23,6 +23,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <time.h>
#include <assert.h>
#include "util.h"
#include "main.h"
@@ -39,7 +40,7 @@
* if this is not NULL. Return the 32 low bits of the keyid.
*/
u32
-keyid_from_skc( PKT_seckey_cert *skc, u32 *keyid )
+keyid_from_skc( PKT_secret_cert *skc, u32 *keyid )
{
u32 lowbits;
u32 dummy_keyid[2];
@@ -53,9 +54,9 @@ keyid_from_skc( PKT_seckey_cert *skc, u32 *keyid )
else if( skc->pubkey_algo == PUBKEY_ALGO_RSA ) {
lowbits = mpi_get_keyid( skc->d.rsa.rsa_n, keyid );
}
- else
- log_bug(NULL);
-
+ else {
+ keyid[0] = keyid[1] = lowbits = 0;
+ }
return lowbits;
}
@@ -65,7 +66,7 @@ keyid_from_skc( PKT_seckey_cert *skc, u32 *keyid )
* if this is not NULL. Return the 32 low bits of the keyid.
*/
u32
-keyid_from_pkc( PKT_pubkey_cert *pkc, u32 *keyid )
+keyid_from_pkc( PKT_public_cert *pkc, u32 *keyid )
{
u32 lowbits;
u32 dummy_keyid[2];
@@ -79,10 +80,94 @@ keyid_from_pkc( PKT_pubkey_cert *pkc, u32 *keyid )
else if( pkc->pubkey_algo == PUBKEY_ALGO_RSA ) {
lowbits = mpi_get_keyid( pkc->d.rsa.rsa_n, keyid );
}
- else
- log_bug(NULL);
+ else {
+ keyid[0] = keyid[1] = lowbits = 0;
+ }
return lowbits;
}
+u32
+keyid_from_sig( PKT_signature *sig, u32 *keyid )
+{
+ if( keyid ) {
+ keyid[0] = sig->keyid[0];
+ keyid[1] = sig->keyid[1];
+ }
+ return sig->keyid[1];
+}
+
+/****************
+ * return the number of bits used in the pkc
+ */
+unsigned
+nbits_from_pkc( PKT_public_cert *pkc )
+{
+ if( pkc->pubkey_algo == PUBKEY_ALGO_ELGAMAL ) {
+ return mpi_get_nbits( pkc->d.elg.p );
+ }
+ else if( pkc->pubkey_algo == PUBKEY_ALGO_RSA ) {
+ return mpi_get_nbits( pkc->d.rsa.rsa_n );
+ }
+ else
+ return 0;
+}
+
+/****************
+ * return the number of bits used in the skc
+ */
+unsigned
+nbits_from_skc( PKT_secret_cert *skc )
+{
+ if( skc->pubkey_algo == PUBKEY_ALGO_ELGAMAL ) {
+ return mpi_get_nbits( skc->d.elg.p );
+ }
+ else if( skc->pubkey_algo == PUBKEY_ALGO_RSA ) {
+ return mpi_get_nbits( skc->d.rsa.rsa_n );
+ }
+ else
+ return 0;
+}
+
+/****************
+ * return a string with the creation date of the pkc
+ * Note: this is alloced in a static buffer.
+ * Format is: yyyy-mm-dd
+ */
+const char *
+datestr_from_pkc( PKT_public_cert *pkc )
+{
+ static char buffer[11+5];
+ struct tm *tp;
+ time_t atime = pkc->timestamp;
+
+ tp = gmtime( &atime );
+ sprintf(buffer,"%04d-%02d-%02d", 1900+tp->tm_year, tp->tm_mon, tp->tm_mday );
+ return buffer;
+}
+
+const char *
+datestr_from_skc( PKT_secret_cert *skc )
+{
+ static char buffer[11+5];
+ struct tm *tp;
+ time_t atime = skc->timestamp;
+
+ tp = gmtime( &atime );
+ sprintf(buffer,"%04d-%02d-%02d", 1900+tp->tm_year, tp->tm_mon, tp->tm_mday );
+ return buffer;
+}
+
+const char *
+datestr_from_sig( PKT_signature *sig )
+{
+ static char buffer[11+5];
+ struct tm *tp;
+ time_t atime = sig->timestamp;
+
+ tp = gmtime( &atime );
+ sprintf(buffer,"%04d-%02d-%02d", 1900+tp->tm_year, tp->tm_mon, tp->tm_mday );
+ return buffer;
+}
+