]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
added time_t conversion stuff to test rrsig validity
authorMiek Gieben <miekg@NLnetLabs.nl>
Wed, 24 Aug 2005 11:20:22 +0000 (11:20 +0000)
committerMiek Gieben <miekg@NLnetLabs.nl>
Wed, 24 Aug 2005 11:20:22 +0000 (11:20 +0000)
ldns/rdata.h
rdata.c
tests/Makefile.in
tests/rrsig-test.c [new file with mode: 0644]
tests/run-test20.c

index 4a5048f149e42badc9c9bacd24f588665e876212..0a10e07519e204c299e1eeb9d3e2961f74add837 100644 (file)
@@ -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 c1906d4487d9d99d03eca4a84b8764c825062989..9e13cfcf71da628f4a0317e361dee5780b0ddb24 100644 (file)
--- 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)
 {
index bcaaa5f365aae8db17a794f8bac48b2f45c5228c..cb405a5cbf11b93f64d35af344944aebd931c66b 100644 (file)
@@ -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 (file)
index 0000000..6a10ba8
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <unistd.h>
+#include <stdbool.h>
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif /* HAVE_STDINT_H */
+
+#include <ldns/dns.h>
+
+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");
+}
index 8623c5def2b063a491c24eda39eab5e75614f269..4f015badda6be15ad899b6a1df2ce9157854d90f 100644 (file)
@@ -97,8 +97,6 @@ main(void)
                ldns_key_print(stdout, privkey);
        }
 
-       exit(1);
-
        dnskey = ldns_key2rr(privkey);
        if (dnskey) {
                ldns_rr_print(stdout, dnskey);