From 1fd4cd403956845c433f558be4ee5d90d9be1e23 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 22 Jan 2002 17:34:20 +0100
Subject: [PATCH] (test_armor): New function.

Rev: src/nettle/testsuite/testutils.c:1.8
Rev: src/nettle/testsuite/testutils.h:1.7
---
 testsuite/testutils.c | 31 +++++++++++++++++++++++++++++++
 testsuite/testutils.h |  6 ++++++
 2 files changed, 37 insertions(+)

diff --git a/testsuite/testutils.c b/testsuite/testutils.c
index b6e4a785..9e5dda13 100644
--- a/testsuite/testutils.c
+++ b/testsuite/testutils.c
@@ -222,6 +222,37 @@ test_hash(const struct nettle_hash *hash,
     FAIL();
 }
 
+void
+test_armor(const struct nettle_armor *armor,
+           unsigned data_length,
+           const uint8_t *data,
+           const uint8_t *ascii)
+{
+  uint8_t *buffer = alloca(1 + strlen(ascii));
+  uint8_t *check = alloca(1 + data_length);
+
+  memset(buffer, 0, 1 + strlen(ascii));
+  memset(check, 0, 1 + data_length);
+
+  if (strlen(ascii) != armor->encode(buffer, data_length, data))
+    FAIL();
+
+  if (!MEMEQ(strlen(ascii), buffer, ascii))
+    FAIL();
+
+  if (buffer[strlen(ascii)])
+    FAIL();  
+
+  if (data_length != armor->decode(check, strlen(ascii), buffer))
+    FAIL();
+
+  if (!MEMEQ(data_length, check, data))
+    FAIL();
+
+  if (check[data_length])
+    FAIL();
+}
+
 #if HAVE_LIBGMP
 #define SIGN(key, hash, msg, signature) do {	\
   hash##_update(&hash, LDATA(msg));		\
diff --git a/testsuite/testutils.h b/testsuite/testutils.h
index 3c2756fe..28f66014 100644
--- a/testsuite/testutils.h
+++ b/testsuite/testutils.h
@@ -58,6 +58,12 @@ test_hash(const struct nettle_hash *hash,
 	  const uint8_t *data,
 	  const uint8_t *digest);
 
+void
+test_armor(const struct nettle_armor *armor,
+           unsigned data_length,
+           const uint8_t *data,
+           const uint8_t *ascii);
+
 #if HAVE_LIBGMP
 void
 test_rsa_md5(struct rsa_public_key *pub,
-- 
GitLab