blob: 49c768fce2447ae438a1ed708732784edc94c3ed (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#!/usr/bin/env nomsu -V2.4.4.3
#
This file defines some actions for hashing files and looking up files by hash.
use "core"
action [file with hash %hash]:
lua> ".."
local Hash = require("openssl.digest")
for filename in io.popen('find -L . -not -path "*/\\\\.*" -type f -name "*.nom"'):lines() do
local file = io.open(filename)
local contents = file:read("*a")
file:close()
local hash = Hash.new("sha1"):final(contents)
local hex = hash:gsub('.', function(c) return string.format('%02x', string.byte(c)) end)
if hex == \%hash then
return filename
end
end
action [hash %, sha1 %]:
%hashlib = (=lua "require('openssl.digest')")
%hash = (=lua "\%hashlib.new('sha1'):final(\%)")
return (..)
=lua "\%hash:gsub('.', function(c) return string.format('%02x', string.byte(c)) end)"
parse [hash of file %filename] as (sha1 (=lua "io.open(\%filename):read('*a')"))
|