From: Miek Gieben Date: Wed, 24 Aug 2005 11:20:22 +0000 (+0000) Subject: added time_t conversion stuff to test rrsig validity X-Git-Tag: release-1.0.0~250 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4d02a6812842bfd5893b64e5a0e4e0c2fedeaebc;p=thirdparty%2Fldns.git added time_t conversion stuff to test rrsig validity --- diff --git a/ldns/rdata.h b/ldns/rdata.h index 4a5048f1..0a10e075 100644 --- a/ldns/rdata.h +++ b/ldns/rdata.h @@ -296,6 +296,13 @@ uint16_t ldns_rdf2native_int16(ldns_rdf *rd); */ uint32_t ldns_rdf2native_int32(ldns_rdf *rd); +/** + * returns the native time_t representation from the rdf. + * \param[in] rd the ldns_rdf to operate on + * \return time_t the value extracted (32 bits currently) + */ +time_t ldns_rdf2native_time_t(ldns_rdf *rd); + /** * converts a ttl value (like 5d2h) to a long. * \param[in] nptr the start of the string diff --git a/rdata.c b/rdata.c index c1906d44..9e13cfcf 100644 --- a/rdata.c +++ b/rdata.c @@ -114,6 +114,20 @@ ldns_rdf2native_int32(ldns_rdf *rd) } } +time_t +ldns_rdf2native_time_t(ldns_rdf *rd) +{ + uint32_t data; + + switch(ldns_rdf_get_type(rd)) { + case LDNS_RDF_TYPE_TIME: + memcpy(&data, ldns_rdf_data(rd), sizeof(data)); + return (time_t)ntohl(data); + default: + return 0; + } +} + struct sockaddr_storage * ldns_rdf2native_sockaddr_storage(ldns_rdf *rd, uint16_t port, size_t *size) { diff --git a/tests/Makefile.in b/tests/Makefile.in index bcaaa5f3..cb405a5c 100644 --- a/tests/Makefile.in +++ b/tests/Makefile.in @@ -19,7 +19,8 @@ LINK = $(CC) $(CFLAGS) $(LDFLAGS) $(LIBS) HEADER = config.h TESTS = run-test0 run-test7 run-test18 run-test19 run-test20 \ - dname-label-test notify run-test-read-zone + dname-label-test notify run-test-read-zone \ + rrsig-test .PHONY: all clean realclean @@ -44,6 +45,9 @@ run-test19: run-test19.o run-test20: run-test20.o $(LINK) -lssl -o $@ $+ + +rrsig-test: rrsig-test.o + $(LINK) -lssl -o $@ $+ run-test-read-zone: run-test-read-zone.o $(LINK) -lssl -o $@ $+ diff --git a/tests/rrsig-test.c b/tests/rrsig-test.c new file mode 100644 index 00000000..6a10ba80 --- /dev/null +++ b/tests/rrsig-test.c @@ -0,0 +1,41 @@ +/* + */ + +#include "config.h" + +#include +#include +#include +#include +#include + +#ifdef HAVE_STDINT_H +#include +#endif /* HAVE_STDINT_H */ + +#include + +int main(void) +{ + ldns_rr *sig; + ldns_rdf *incep, *expir; + + time_t t_incep, t_expir, t_now; + + sig = ldns_rr_new_frm_str("jelte.nlnetlabs.nl. 18000 IN RRSIG NSEC RSASHA1 3 18000 20050913235001 20050814235001 43791 nlnetlabs.nl. epWGR0WkhWQ1h0eXvU89W57xwI0xuUlWtvvUnABQVmUfZ2nGllIy2KLR5cfgpB5UH7beASrAo78AlPddPCnH50OYNjllesDy9HLderQtjQoi47SPPluLC6v3Fwqq64Zv0wf2fPzJqDSnOOrQPVzIuB3IDv5XD4M5t8Vze8QZ8lA=", 0, NULL); + + ldns_rr_print(stdout, sig); + + t_now = time(NULL); + incep = ldns_rr_rrsig_inception(sig); + t_incep = ldns_rdf2native_time_t(incep); + expir = ldns_rr_rrsig_expiration(sig); + t_expir = ldns_rdf2native_time_t(expir); + + printf("inception: [now %d] %d\n", t_now, t_incep); + ldns_rdf_print(stdout, incep); + printf("\n"); + printf("expiration: %d\n", t_expir); + ldns_rdf_print(stdout, expir); + printf("\n"); +} diff --git a/tests/run-test20.c b/tests/run-test20.c index 8623c5de..4f015bad 100644 --- a/tests/run-test20.c +++ b/tests/run-test20.c @@ -97,8 +97,6 @@ main(void) ldns_key_print(stdout, privkey); } - exit(1); - dnskey = ldns_key2rr(privkey); if (dnskey) { ldns_rr_print(stdout, dnskey);