bool hash_store_build_reply(struct hash_store* self, struct ndn_charbuf* reply, const uint8_t* hash, const uint8_t* payload, size_t payloadsz) { ndnb_element_begin(reply, NDN_DTAG_ContentObject); ndnb_element_begin(reply, NDN_DTAG_Signature); ndnb_tagged_putf(reply, NDN_DTAG_DigestAlgorithm, "SHA256"); ndnb_append_tagged_blob(reply, NDN_DTAG_SignatureBits, hash, SEGMENT_HASHSZ); ndnb_element_end(reply);//Signature ndnb_element_begin(reply, NDN_DTAG_Name); ndnb_append_tagged_blob(reply, NDN_DTAG_Component, REPO_SHA256, sizeof(REPO_SHA256)-1); ndnb_append_tagged_blob(reply, NDN_DTAG_Component, hash, SEGMENT_HASHSZ); ndnb_element_end(reply);//Name ndnb_element_begin(reply, NDN_DTAG_SignedInfo); ndnb_append_tagged_blob(reply, NDN_DTAG_PublisherPublicKeyDigest, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 32); ndnb_element_begin(reply, NDN_DTAG_Timestamp); ndnb_append_now_blob(reply, NDN_MARKER_NONE); ndnb_element_end(reply);//Timestamp ndnb_element_end(reply);//SignedInfo ndnb_append_tagged_blob(reply, NDN_DTAG_Content, payload, payloadsz); ndnb_element_end(reply);//ContentObject return true; }
/** * Extend a Name with a new version stamp * @param h is the the ndn handle. * May be NULL. This procedure does not use the connection. * @param name is a ndnb-encoded Name prefix. By default it gets extended * in-place with one additional Component that conforms to the * versioning profile and is based on the supplied time, unless a * version component is already present. * @param versioning_flags modifies the default behavior: * NDN_V_REPLACE causes the last component to be replaced if it * appears to be a version stamp. If NDN_V_HIGH is set as well, an * attempt will be made to generate a new version stamp that is * later than the existing one, or to return an error. * NDN_V_NOW bases the version on the current time rather than the * supplied time. * NDN_V_NESTOK will allow the new version component to be appended * even if there is one there (this makes no difference if NDN_V_REPLACE * is also set). * @param secs is the desired time, in seconds since epoch * (ignored if NDN_V_NOW is set). * @param nsecs is the number of nanoseconds. * @returns -1 for error, 0 for success. */ int ndn_create_version(struct ndn *h, struct ndn_charbuf *name, int versioning_flags, intmax_t secs, int nsecs) { size_t i; size_t j; size_t lc = 0; size_t oc = 0; int n; struct ndn_indexbuf *nix = NULL; int myres = -1; int already_versioned = 0; int ok_flags = (NDN_V_REPLACE | NDN_V_HIGH | NDN_V_NOW | NDN_V_NESTOK); // XXX - right now we ignore h, but in the future we may use it to try to avoid non-monotonicies in the versions. nix = ndn_indexbuf_create(); n = ndn_name_split(name, nix); if (n < 0) goto Finish; if ((versioning_flags & ~ok_flags) != 0) goto Finish; /* Check for existing version component */ if (n >= 1) { oc = nix->buf[n-1]; lc = nix->buf[n] - oc; if (lc <= 11 && lc >= 6 && name->buf[oc + 2] == NDN_MARKER_VERSION) already_versioned = 1; } myres = 0; if (already_versioned && (versioning_flags & (NDN_V_REPLACE | NDN_V_NESTOK)) == 0) goto Finish; name->length -= 1; /* Strip name closer */ i = name->length; myres |= ndn_charbuf_append_tt(name, NDN_DTAG_Component, NDN_DTAG); if ((versioning_flags & NDN_V_NOW) != 0) myres |= ndnb_append_now_blob(name, NDN_MARKER_VERSION); else { myres |= ndnb_append_timestamp_blob(name, NDN_MARKER_VERSION, secs, nsecs); } myres |= ndn_charbuf_append_closer(name); /* </Component> */ if (myres < 0) { name->length = i; goto CloseName; } j = name->length; if (already_versioned && (versioning_flags & NDN_V_REPLACE) != 0) { oc = nix->buf[n-1]; lc = nix->buf[n] - oc; if ((versioning_flags & NDN_V_HIGH) != 0 && memcmp(name->buf + oc, name->buf + i, j - i) > 0) { /* Supplied version is in the future. */ name->length = i; // XXX - we could try harder to make this work, for now just error out myres = -1; goto CloseName; } memmove(name->buf + oc, name->buf + i, j - i); name->length -= lc; } CloseName: myres |= ndn_charbuf_append_closer(name); /* </Name> */ Finish: myres = (myres < 0) ? -1 : 0; ndn_indexbuf_destroy(&nix); return(myres); }