From e7e13ce8b4951c049b33959c82171472f463c80f Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Wed, 15 May 2019 21:04:32 -0500 Subject: [PATCH] IntegrityCheck stores raw hash internally --- lib/dhall/ast.rb | 8 ++++++-- lib/dhall/binary.rb | 6 +++++- lib/dhall/parser.rb | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/dhall/ast.rb b/lib/dhall/ast.rb index 7e6a4e6..5681541 100644 --- a/lib/dhall/ast.rb +++ b/lib/dhall/ast.rb @@ -1203,7 +1203,11 @@ module Dhall end def to_s - "#{@protocol}:#{@data}" + "#{@protocol}:#{hexdigest}" + end + + def hexdigest + @data&.unpack("H*")&.first&.encode(Encoding::UTF_8) end def check(expr) @@ -1216,7 +1220,7 @@ module Dhall end def as_json - @protocol == :nocheck ? nil : [@protocol, @data] + @protocol == :nocheck ? nil : [@protocol, hexdigest] end end diff --git a/lib/dhall/binary.rb b/lib/dhall/binary.rb index c8fdfcb..a3a9d11 100644 --- a/lib/dhall/binary.rb +++ b/lib/dhall/binary.rb @@ -193,8 +193,12 @@ module Dhall def self.decode(integrity_check, import_type, path_type, *parts) parts[0] = Dhall.decode(parts[0]) if path_type < 2 && !parts[0].nil? + check = if integrity_check + IntegrityCheck.new(integrity_check[0], [integrity_check[1]].pack("H*")) + end + new( - IntegrityCheck.new(*integrity_check), + check, IMPORT_TYPES[import_type], PATH_TYPES[path_type].new(*parts) ) diff --git a/lib/dhall/parser.rb b/lib/dhall/parser.rb index 9b3706b..5418e73 100644 --- a/lib/dhall/parser.rb +++ b/lib/dhall/parser.rb @@ -525,7 +525,7 @@ module Dhall module Hash def value protocol, data = string.split(/:/, 2) - Dhall::Import::IntegrityCheck.new(protocol, data) + Dhall::Import::IntegrityCheck.new(protocol, [data].pack("H*")) end end -- 2.45.2