Class: Dhall::Import::IntegrityCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/dhall/ast.rb,
lib/dhall/binary.rb

Direct Known Subclasses

NoIntegrityCheck

Defined Under Namespace

Classes: FailureException

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.decode(integrity_check) ⇒ Object



224
225
226
227
228
229
230
231
232
# File 'lib/dhall/binary.rb', line 224

def self.decode(integrity_check)
	return unless integrity_check

	IntegrityCheck.new(
		Multihashes.decode(integrity_check).select { |k, _|
			[:code, :digest].include?(k)
		}
	)
end

Instance Method Details

#as_jsonObject



1355
1356
1357
# File 'lib/dhall/ast.rb', line 1355

def as_json
	Multihashes.encode(digest, Multihashes::TABLE[code])
end

#check(expr) ⇒ Object

Raises:



1347
1348
1349
1350
1351
1352
1353
# File 'lib/dhall/ast.rb', line 1347

def check(expr)
	expr = expr.normalize
	return expr if expr.cache_key == to_s

	raise FailureException, "#{expr} hash #{expr.cache_key}" \
	                        " does not match #{self}"
end

#hexdigestObject



1339
1340
1341
# File 'lib/dhall/ast.rb', line 1339

def hexdigest
	digest.unpack("H*").first.encode(Encoding::UTF_8)
end

#ipfsObject



1343
1344
1345
# File 'lib/dhall/ast.rb', line 1343

def ipfs
	"/ipfs/b#{Base32.encode("\x01\x55" + as_json).downcase.sub(/=*$/, "")}"
end

#to_sObject



1335
1336
1337
# File 'lib/dhall/ast.rb', line 1335

def to_s
	"#{Multihashes::TABLE[code].sub(/\Asha2-/, "sha")}:#{hexdigest}"
end