From 89e9cbbb069ac09be5f9d8a449fc19394bd13bd07155e7e88922f224b74622d7 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Sun, 15 Mar 2026 10:36:49 +0300 Subject: [PATCH] DSC_HASHES -> DSC_HASHERS And also make it newline-separated with space separated key-value. To be compatible with newest meta4ra utilities and BASS project. --- CHECKSUM | 8 ++++---- dsc | 26 ++++++++++++++------------ t/csum.t | 4 ++-- t/setup.rc | 8 +++++--- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/CHECKSUM b/CHECKSUM index 55a57da..d374738 100644 --- a/CHECKSUM +++ b/CHECKSUM @@ -2,10 +2,10 @@ There is ability to integrity protect the exported configuration. Exported txtar contains trailing ".csum" pseudo file with one or multiple hashes of the digested data. -DSC_HASHES environment variables specified what hashes must be included -and invoked. For example "blake2b-512:b2sum,skein-512:skein512" value -means, that BLAKE2b-512 is calculated by calling "b2sum" utility, and -Skein-512 by "skein512". +DSC_HASHERS environment variables specified what hashers must be +included and invoked. For example "blake2b-512 b2sum\nskein-512 skein512" +value means, that BLAKE2b-512 is calculated by calling "b2sum" utility, +and Skein-512 by "skein512". "dsc csum" command can be used to calculate hashes over the arbitrary data. "dsc import-check" can be used to verify piped in configuration diff --git a/dsc b/dsc index 779367c..ececf81 100755 --- a/dsc +++ b/dsc @@ -42,8 +42,8 @@ Environmental variables: $DSC_SCHEMA -- path to the schema definition $DSC_STASH -- path to stashed/unsaved state $DSC_SAVED -- path to committed/saved state - $DSC_HASHES -- sha2-512:sha512 by default - Comma-separated list of hash-name:cmd pairs + $DSC_HASHERS -- "sha2-512 sha512" by default. + Newline-separated list of "hash-name cmd" pairs There are two kinds of options: * array/list ones, which are identified with /*/ in "list"'s @@ -57,17 +57,19 @@ set CopyBufLen [expr {128 * 1024}] if {[info exists env(DSC_SCHEMA)]} {set Schema $env(DSC_SCHEMA)} {set Schema schema} if {[info exists env(DSC_STASH)]} {set Stash $env(DSC_STASH)} {set Stash stash} if {[info exists env(DSC_SAVED)]} {set Saved $env(DSC_SAVED)} {set Saved saved} -if {[info exists env(DSC_HASHES)]} { - set Hashes [list] - foreach pair [split $env(DSC_HASHES) ,] { - set cols [split $pair :] - if {[llength $cols] != 2} { - error "bad DSC_HASHES" - } - lappend Hashes [lindex $cols 0] [lindex $cols 1] +if {[info exists env(DSC_HASHERS)]} { + set Hashers [list] + foreach pair [split $env(DSC_HASHERS) "\n"] { + set idx [string first " " $pair] + if {$idx <= 0} { + continue + } + lappend Hashers \ + [string range $pair 0 [expr {$idx-1}]] \ + [string range $pair [expr {$idx+1}] end] } } { - set Hashes [list sha2-512 sha512] + set Hashers [list sha2-512 sha512] } proc readents {root typ} { @@ -350,7 +352,7 @@ switch [lindex $argv 0] { } csum { set hsh [list] - foreach {name cmd} $Hashes { + foreach {name cmd} $Hashers { lassign [pipe] r w set fh [open [list |$cmd >@$w] w] fconfigure $fh -translation binary diff --git a/t/csum.t b/t/csum.t index 02d5849..5167224 100755 --- a/t/csum.t +++ b/t/csum.t @@ -23,7 +23,7 @@ printf "%s\n" "-- .csum --" >>expected echo "whatever hash" >>expected test_expect_success "wrong csum" "! dsc import-check out" cat >expected <>expected cat hsh >>expected test_expect_success "cmp" "test_cmp out expected" -DSC_HASHES="" +DSC_HASHERS="" test_expect_success "empty hashes" "dsc export >out" cat >expected </dev/null >/dev/null ; then - DSC_HASHES="skein-512:skein512,$DSC_HASHES" + DSC_HASHERS="skein-512 skein512 +$DSC_HASHERS" fi if command -v b2sum 2>/dev/null >/dev/null ; then - DSC_HASHES="blake2b-512:b2sum,$DSC_HASHES" + DSC_HASHERS="blake2b-512 b2sum +$DSC_HASHERS" fi -- 2.52.0