From patchwork Mon Jul 13 02:49:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "brian m. carlson" X-Patchwork-Id: 11658581 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5A9B13B1 for ; Mon, 13 Jul 2020 02:50:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9D0B920725 for ; Mon, 13 Jul 2020 02:50:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (3072-bit key) header.d=crustytoothpaste.net header.i=@crustytoothpaste.net header.b="n7ThMaqy" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728711AbgGMCt7 (ORCPT ); Sun, 12 Jul 2020 22:49:59 -0400 Received: from injection.crustytoothpaste.net ([192.241.140.119]:40638 "EHLO injection.crustytoothpaste.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728497AbgGMCtn (ORCPT ); Sun, 12 Jul 2020 22:49:43 -0400 Received: from camp.crustytoothpaste.net (unknown [IPv6:2001:470:b978:101:b610:a2f0:36c1:12e3]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by injection.crustytoothpaste.net (Postfix) with ESMTPSA id CDBF160A78; Mon, 13 Jul 2020 02:49:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=crustytoothpaste.net; s=default; t=1594608580; bh=9s046Lg3ATkwRo1CInBpkC4zm/IZy1NRAcoTYzhZTno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From:Reply-To: Subject:Date:To:CC:Resent-Date:Resent-From:Resent-To:Resent-Cc: In-Reply-To:References:Content-Type:Content-Disposition; b=n7ThMaqyWqwQjzynm0F2I8xChpz/y3DHStodjaefRPxJ24GJ6pdn65G5lYCyArKJG yx5rT1eesAWkal6uqR3Ldmrc3O0nd+Wu2OH1Sw3C6VFqS7C+jCoNFYmxXlECX0gs93 VWpLCEtGB9a/hH/X/xZt2dLICdGaB8ALMZIv3sGYTfq9F6l/sATStR9RBMxcf9dMsa xX/eWbgFW47J9Ig7H2XZbfxpwy6v9GpZDvI6q1lpo2MV3DzK9Pz8JSkCuvDn8NAFTb kh+1OT3TNIyhCRtk9GI4MTnsoz2cJm52qas0EDYgU9kgGsEhFaXwbz4KsRXAlT109l WZNXAuYHl7t9jCE7f+aTKOOEnqYH8xbrPREgjPVxmN67bDya/xJvDObGXzKB97vfNl CLTLnJ3L5djeIC9Zvut8shuACR7jgdsfU3X3/6YibkMmDCxA2ptNXQ++E8mWBCND1y uucPWDIhN76DxquAs3cpnGlLzSkWVyonW21WiYDq0Z5HZVhEN5J From: "brian m. carlson" To: Cc: Denton Liu , Derrick Stolee Subject: [PATCH v2 34/39] t: add test_oid option to select hash algorithm Date: Mon, 13 Jul 2020 02:49:04 +0000 Message-Id: <20200713024909.3714837-35-sandals@crustytoothpaste.net> X-Mailer: git-send-email 2.27.0.353.gb9a2d1a020 In-Reply-To: <20200713024909.3714837-1-sandals@crustytoothpaste.net> References: <20200713024909.3714837-1-sandals@crustytoothpaste.net> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In some tests, we have data files which are written with a particular hash algorithm. Instead of keeping two copies of the test files, we can keep one, and translate the value on the fly. In order to do so, we'll need to read both the source algorithm and the current algorithm, so add an optional flag to the test_oid helper that lets us read look up a value for a specified hash algorithm. This should not cause any conflicts with existing tests, since key arguments to test_oid are allowed to contains only shell identifier characters. Signed-off-by: brian m. carlson --- t/t0000-basic.sh | 11 +++++++++++ t/test-lib-functions.sh | 12 +++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 2ff176cd5d..47d6b502c2 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -928,6 +928,17 @@ test_expect_success 'test_oid can look up data for SHA-256' ' test "$hexsz" -eq 64 ' +test_expect_success 'test_oid can look up data a specified algorithm' ' + rawsz="$(test_oid --hash=sha1 rawsz)" && + hexsz="$(test_oid --hash=sha1 hexsz)" && + test "$rawsz" -eq 20 && + test "$hexsz" -eq 40 && + rawsz="$(test_oid --hash=sha256 rawsz)" && + hexsz="$(test_oid --hash=sha256 hexsz)" && + test "$rawsz" -eq 32 && + test "$hexsz" -eq 64 +' + test_expect_success 'test_bool_env' ' ( sane_unset envvar && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 3103be8a32..d243ff43f3 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1468,7 +1468,17 @@ test_oid_cache () { # Look up a per-hash value based on a key ($1). The value must have been loaded # by test_oid_init or test_oid_cache. test_oid () { - local var="test_oid_${test_hash_algo}_$1" && + local algo="${test_hash_algo}" && + + case "$1" in + --hash=*) + algo="${1#--hash=}" && + shift;; + *) + ;; + esac && + + local var="test_oid_${algo}_$1" && # If the variable is unset, we must be missing an entry for this # key-hash pair, so exit with an error.