named_information v1.0.1

A crystal lang implementation of rfc6920 (Naming Things with Hashes)

named_information

A crystal lang implementation of rfc6920

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      named_information:
        github: spider-gazelle/named_information
    
  2. Run shards install

Usage

basic usage

require "named_information"

NamedInformation.generate_uri("Hello World!") #=> "ni:///sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk"

hash = NamedInformation::Hash.new "ni://example.com/sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk"
hash.matches?("Hello World!") # => true
hash.authority # => "example.com"
hash.algorithm # => "sha-256"

other_hash = NamedInformation::Hash.new "sha-256;f4OxZX_x_FO5LcGBSKHWXfwtSx-j1ncoSt3SABJtkGk"

hash == other_hash # => true

Works with binary data

require "named_information"

hash = NamedInformation::Hash.new(bytes)
hash.to_slice

hash = NamedInformation::Hash.new(uint128)
hash.to_u128

Contributors

Repository

named_information

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 1
  • 3 months ago
  • October 11, 2023
License

MIT License

Links
Synced at

Sat, 18 May 2024 05:32:41 GMT

Languages