[master] f3617f9 Add smp_copy_signspace() and smp_trunc_signspace() utility functions

Martin Blix Grydeland martin at varnish-cache.org
Wed Oct 10 09:49:18 CEST 2012


commit f3617f9d85cf2bfba4b778fa10a17bdc0862df11
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Wed Sep 26 13:25:38 2012 +0200

    Add smp_copy_signspace() and smp_trunc_signspace() utility functions
    
    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.

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.
  */
 



More information about the varnish-commit mailing list