[PATCH 03/13] Add smp_copy_signspace() and smp_trunc_signspace() utility functions
Martin Blix Grydeland
martin at varnish-software.com
Mon Oct 1 12:26:10 CEST 2012
smp_copy_signspace() will copy the sign data of one space onto another.
smp_trunc_signspace() will truncate the signed space to len bytes and
resign the space.
---
bin/varnishd/storage/storage_persistent.h | 3 +++
bin/varnishd/storage/storage_persistent_subr.c | 31 ++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/bin/varnishd/storage/storage_persistent.h b/bin/varnishd/storage/storage_persistent.h
index ec97d3e..c4837b9 100644
--- a/bin/varnishd/storage/storage_persistent.h
+++ b/bin/varnishd/storage/storage_persistent.h
@@ -207,6 +207,9 @@ void smp_def_signspace(const struct smp_sc *sc, struct smp_signspace *spc,
int smp_chk_signspace(struct smp_signspace *spc);
void smp_append_signspace(struct smp_signspace *spc, uint32_t len);
void smp_reset_signspace(struct smp_signspace *spc);
+void smp_copy_signspace(struct smp_signspace *dst,
+ const struct smp_signspace *src);
+void smp_trunc_signspace(struct smp_signspace *spc, uint32_t len);
void smp_newsilo(struct smp_sc *sc);
int smp_valid_silo(struct smp_sc *sc);
diff --git a/bin/varnishd/storage/storage_persistent_subr.c b/bin/varnishd/storage/storage_persistent_subr.c
index ac93544..f7c748e 100644
--- a/bin/varnishd/storage/storage_persistent_subr.c
+++ b/bin/varnishd/storage/storage_persistent_subr.c
@@ -224,6 +224,37 @@ smp_reset_signspace(struct smp_signspace *spc)
}
/*--------------------------------------------------------------------
+ * Copy the contents of one signspace to another. Prepare for
+ * appending.
+ */
+
+void
+smp_copy_signspace(struct smp_signspace *dst, const struct smp_signspace *src)
+{
+ assert(SIGNSPACE_LEN(src) <= dst->size);
+ smp_reset_signspace(dst);
+ memcpy(SIGNSPACE_DATA(dst), SIGNSPACE_DATA(src), SIGNSPACE_LEN(src));
+ smp_append_signspace(dst, SIGNSPACE_LEN(src));
+ assert(SIGNSPACE_LEN(src) == SIGNSPACE_LEN(dst));
+}
+
+/*--------------------------------------------------------------------
+ * Reapplies the sign over the len first bytes of the
+ * signspace. Prepares for appending.
+ */
+
+void
+smp_trunc_signspace(struct smp_signspace *spc, uint32_t len)
+{
+ assert(len <= SIGNSPACE_LEN(spc));
+ spc->ctx.ss->length = 0;
+ SHA256_Init(&spc->ctx.ctx);
+ SHA256_Update(&spc->ctx.ctx, spc->ctx.ss,
+ offsetof(struct smp_sign, length));
+ smp_append_signspace(spc, len);
+}
+
+/*--------------------------------------------------------------------
* Create a new signature space and force the signature to backing store.
*/
--
1.7.9.5
More information about the varnish-dev
mailing list