]> git.ipfire.org Git - thirdparty/ldns.git/commitdiff
Accessor functions for LDNS_RDF_TYPE_HIP rdfs
authorWillem Toorop <willem@nlnetlabs.nl>
Tue, 1 Oct 2013 13:58:26 +0000 (15:58 +0200)
committerWillem Toorop <willem@nlnetlabs.nl>
Tue, 1 Oct 2013 13:58:26 +0000 (15:58 +0200)
error.c
ldns/error.h
ldns/rdata.h
rdata.c

diff --git a/error.c b/error.c
index 6c3aa196b85d2207d69cc7161d42eb9c3ba783f6..82ea61a1dcc2e0ce4a762f95a211fe46f8f252f2 100644 (file)
--- a/error.c
+++ b/error.c
@@ -140,6 +140,9 @@ ldns_lookup_table ldns_error_str[] = {
         { LDNS_STATUS_TYPE_NOT_IN_BITMAP, 
                "The RR type bitmap rdata field did not have "
                "a bit reserved for the specific RR type" },
+        { LDNS_STATUS_INVALID_RDF_TYPE, 
+               "The rdata field was not of the expected type" },
+        { LDNS_STATUS_RDATA_OVERFLOW, "Rdata size overflow" },
        { 0, NULL }
 };
 
index e70f8d6aa093694714e6e4081657242444b6eb46..41b99ad146d98f3eb1375db2334aaa17bb0a33ac 100644 (file)
@@ -125,6 +125,8 @@ enum ldns_enum_status {
        LDNS_STATUS_WIRE_RDATA_ERR,
        LDNS_STATUS_INVALID_TAG,
        LDNS_STATUS_TYPE_NOT_IN_BITMAP,
+       LDNS_STATUS_INVALID_RDF_TYPE,
+       LDNS_STATUS_RDATA_OVERFLOW,
 };
 typedef enum ldns_enum_status ldns_status;
 
index 7a9afb45186a18842309f1e102c197f6a462f741..1866e8fc066fdb6acf49aef68bef0812b9089c7e 100644 (file)
@@ -408,6 +408,34 @@ ldns_rdf *ldns_rdf_clone(const ldns_rdf *rd);
  */
 int ldns_rdf_compare(const ldns_rdf *rd1, const ldns_rdf *rd2);
 
+/**
+ * Gets the algorithm value, the HIT and Public Key data from the rdf with
+ * type LDNS_RDF_TYPE_HIP.
+ * \param[in] rdf the rdf with type LDNS_RDF_TYPE_HIP
+ * \param[out] alg      the algorithm
+ * \param[out] hit_size the size of the HIT data
+ * \param[out] hit      the hit data
+ * \param[out] pk_size  the size of the Public Key data
+ * \param[out] pk       the  Public Key data
+ * \return LDNS_STATUS_OK on success, and the error otherwise
+ */
+ldns_status ldns_rdf_hip_get_alg_hit_pk(ldns_rdf *rdf, uint8_t* alg,
+               uint8_t *hit_size, uint8_t** hit,
+               uint16_t *pk_size, uint8_t** pk);
+
+/**
+ * Creates a new LDNS_RDF_TYPE_HIP rdf from given data.
+ * \param[out] rdf      the newly created LDNS_RDF_TYPE_HIP rdf
+ * \param[in]  alg      the algorithm
+ * \param[in]  hit_size the size of the HIT data
+ * \param[in]  hit      the hit data
+ * \param[in]  pk_size  the size of the Public Key data
+ * \param[in]  pk       the  Public Key data
+ * \return LDNS_STATUS_OK on success, and the error otherwise
+ */
+ldns_status ldns_rdf_hip_new_frm_alg_hit_pk(ldns_rdf** rdf, uint8_t alg,
+               uint8_t hit_size, uint8_t *hit, uint16_t pk_size, uint8_t *pk);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/rdata.c b/rdata.c
index 2af1ee1e0c426a33a05b22535b5ae4b4ff5f274e..64004031225e8697573e7e9cdc5d1c85a81de0b7 100644 (file)
--- a/rdata.c
+++ b/rdata.c
@@ -518,6 +518,67 @@ ldns_rdf_address_reverse(ldns_rdf *rd)
        return rev;
 }
 
+ldns_status
+ldns_rdf_hip_get_alg_hit_pk(ldns_rdf *rdf, uint8_t* alg,
+                            uint8_t *hit_size, uint8_t** hit,
+                            uint16_t *pk_size, uint8_t** pk)
+{
+       uint8_t *data;
+       size_t rdf_size;
+
+       if (! rdf || ! alg || ! hit || ! hit_size || ! pk || ! pk_size) {
+               return LDNS_STATUS_INVALID_POINTER;
+
+       } else if (ldns_rdf_get_type(rdf) != LDNS_RDF_TYPE_HIP) {
+               return LDNS_STATUS_INVALID_RDF_TYPE;
+
+       }
+               else if ((rdf_size = ldns_rdf_size(rdf)) < 6) {
+               return LDNS_STATUS_WIRE_RDATA_ERR;
+       }
+       data = ldns_rdf_data(rdf);
+       *hit_size = data[0];
+       *alg      = data[1];
+       *pk_size  = ldns_read_uint16(data + 2);
+       *hit      = data + 4;
+       *pk       = data + 4 + *hit_size;
+       if (*hit_size == 0 || *pk_size == 0 ||
+                       rdf_size < (size_t) *hit_size + *pk_size + 4) {
+               return LDNS_STATUS_WIRE_RDATA_ERR;
+       }
+       return LDNS_STATUS_OK;
+}
+
+ldns_status
+ldns_rdf_hip_new_frm_alg_hit_pk(ldns_rdf** rdf, uint8_t alg,
+                                uint8_t hit_size, uint8_t *hit,
+                               uint16_t pk_size, uint8_t *pk)
+{
+       uint8_t *data;
+
+       if (! rdf) {
+               return LDNS_STATUS_INVALID_POINTER;
+       }
+       if (4 + hit_size + pk_size > LDNS_MAX_RDFLEN) {
+               return LDNS_STATUS_RDATA_OVERFLOW;
+       }
+       data = LDNS_XMALLOC(uint8_t, 4 + hit_size + pk_size);
+       if (data == NULL) {
+               return LDNS_STATUS_MEM_ERR;
+       }
+       data[0] = hit_size;
+       data[1] = alg;
+       ldns_write_uint16(data + 2, pk_size);
+       memcpy(data + 4, hit, hit_size);
+       memcpy(data + 4 + hit_size, pk, pk_size);
+       *rdf = ldns_rdf_new(LDNS_RDF_TYPE_HIP, 4 + hit_size + pk_size, data);
+       if (! *rdf) {
+               LDNS_FREE(data);
+               return LDNS_STATUS_MEM_ERR;
+       }
+       return LDNS_STATUS_OK;
+}
+
 ldns_status
 ldns_octet(char *word, size_t *length)
 {