base58 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33ccbcef765a46e1e856bc882fc45b75b727de51da69e5bece5e097bc39d1dbd
4
- data.tar.gz: 7eb54e225d04709b747c16b1d741b645d7c42b2911dd5da83a4111104b00b26e
3
+ metadata.gz: c9b47376957f4dbd7b96af742f18a5a0acef4fbcd47d7df25d1063051d52cb3f
4
+ data.tar.gz: e358735d555fede75daa17a1e425738ebd6e7921a74be2e028a0f2d0b4e16e5a
5
5
  SHA512:
6
- metadata.gz: d6cb74b302d8f367860fb85bfd0bdc842bb57064a2c852bd03e4fafe215fc850deb3efc4ae98ca21380c8f2939eb92f17886a4a29bcde37b77524292cdbd80fa
7
- data.tar.gz: cb77134f325a5ed494727f1f2c5662e1332f57666ee824d74db8929ea7d04990823531b666c4cca3877633a30bc56b8ee75cf1b2d57a72c448c1ec268e57fd47
6
+ metadata.gz: 1349c672d885fe401e8d2c7f98d219394ec76d03116ffe9323ec49cc10648df453742951020fb5f2f68f2ed7a6ec1867cdd851d99a34cfa3b96163e24a9ebbaa
7
+ data.tar.gz: 88a6a954d7d49c22dc2fa81b15686b8c260b27acec06db06236987e8b12137e8a4335f912867d9cddfa32d11464484a30e97fbb9ef9319181c6afed6e77a58ac
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ = 0.2.2 [2017-01-11]
2
+ - Fix for incorrect encoding of leading-zeroes. Thanks to @joelnordell.
3
+
1
4
  = 0.2.1 [2017-01-08]
2
5
  - Bitcoin-style leading-zeroes encoding. Thanks to @joelnordell.
3
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.2.2
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: base58 0.2.1 ruby lib
5
+ # stub: base58 0.2.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "base58".freeze
9
- s.version = "0.2.1"
9
+ s.version = "0.2.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Douglas F Shearer".freeze]
14
- s.date = "2018-01-08"
14
+ s.date = "2018-01-11"
15
15
  s.description = "Base58 is a Ruby library for converting ints or binaries to and from base58.".freeze
16
16
  s.email = "dougal.s@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -53,7 +53,7 @@ class Base58
53
53
  prefix = ''
54
54
  end
55
55
 
56
- prefix + int_to_base58(binary_val.bytes.inject{|a,b|(a<<8)+b}, alphabet)
56
+ prefix + int_to_base58(binary_val.unpack('H*')[0].to_i(16), alphabet)
57
57
  end
58
58
 
59
59
  # Converts a base58 string to an ASCII-8BIT (binary) encoded string.
@@ -63,7 +63,16 @@ class Base58
63
63
  raise ArgumentError, 'Invalid alphabet selection.' unless ALPHABETS.include?(alphabet)
64
64
  nzeroes = base58_val.chars.find_index{|c| c != ALPHABETS[alphabet][0]} || base58_val.length-1
65
65
  prefix = nzeroes < 0 ? '' : '00' * nzeroes
66
- [prefix + base58_to_int(base58_val, alphabet).to_s(16)].pack('H*')
66
+ [prefix + Private::int_to_hex(base58_to_int(base58_val, alphabet))].pack('H*')
67
+ end
68
+
69
+ module Private
70
+ def self.int_to_hex int
71
+ hex = int.to_s(16)
72
+ # The hex string must always consist of an even number of characters,
73
+ # otherwise the pack() parsing will be misaligned.
74
+ (hex.length % 2 == 0) ? hex : ('0'+hex)
75
+ end
67
76
  end
68
77
 
69
78
  class << self
@@ -531,7 +531,8 @@ EXAMPLES = {
531
531
  "6hHHZB" => "\xCE\xE3\x15Y".force_encoding('BINARY'),
532
532
  "6hHKum" => "\xCE\xE3)\x00".force_encoding('BINARY'),
533
533
  "6hLgFW" => "\xCE\xEA\xAA(".force_encoding('BINARY'),
534
- "6hBRKR" => "\xCE\xD1\x9Ek".force_encoding('BINARY')
534
+ "6hBRKR" => "\xCE\xD1\x9Ek".force_encoding('BINARY'),
535
+ "7xBSG3j7NgPksBpPnX1G7y19EuAy4swQexDoECfWdys" => "\x01\xAD<l'\xAF!\x96N\x93u\x93\xE2\xAF\x92p\x96=\x89n\xD7\x953\x17\x12\x8E\xBD\xA2\x04\x84~Z".force_encoding('BINARY')
535
536
  },
536
537
  :bitcoin => {
537
538
  "6Hknds" => "\xCE\xE99\x86".force_encoding('BINARY'),
@@ -539,7 +540,8 @@ EXAMPLES = {
539
540
  "6Hiizc" => "\xCE\xE3\x15Y".force_encoding('BINARY'),
540
541
  "6HikVM" => "\xCE\xE3)\x00".force_encoding('BINARY'),
541
542
  "6HmGgw" => "\xCE\xEA\xAA(".force_encoding('BINARY'),
542
- "6Hcrkr" => "\xCE\xD1\x9Ek".force_encoding('BINARY')
543
+ "6Hcrkr" => "\xCE\xD1\x9Ek".force_encoding('BINARY'),
544
+ "7Ycsh3K7oGpLTcQpNx1h7Z19fVbZ4TXqEYePfdFwDZT" => "\x01\xAD<l'\xAF!\x96N\x93u\x93\xE2\xAF\x92p\x96=\x89n\xD7\x953\x17\x12\x8E\xBD\xA2\x04\x84~Z".force_encoding('BINARY')
543
545
  },
544
546
  :ripple => {
545
547
  "aHk8d1" => "\xCE\xE99\x86".force_encoding('BINARY'),
@@ -547,7 +549,8 @@ EXAMPLES = {
547
549
  "aH55zc" => "\xCE\xE3\x15Y".force_encoding('BINARY'),
548
550
  "aH5kVM" => "\xCE\xE3)\x00".force_encoding('BINARY'),
549
551
  "aHmGgA" => "\xCE\xEA\xAA(".force_encoding('BINARY'),
550
- "aHciki" => "\xCE\xD1\x9Ek".force_encoding('BINARY')
552
+ "aHciki" => "\xCE\xD1\x9Ek".force_encoding('BINARY'),
553
+ "fYc16sKfoGFLTcQF4xr6fZr9CVbZhTXqNYePCdEADZT" => "\x01\xAD<l'\xAF!\x96N\x93u\x93\xE2\xAF\x92p\x96=\x89n\xD7\x953\x17\x12\x8E\xBD\xA2\x04\x84~Z".force_encoding('BINARY')
551
554
  }
552
555
  }
553
556
 
@@ -708,6 +711,15 @@ EXAMPLES = {
708
711
  end
709
712
  end
710
713
 
714
+ def test_base58_to_binary_round_trip
715
+ BINARY_STRING_EXAMPLES.each do |alphabet, examples|
716
+ examples.each do |base_58, binary|
717
+ assert_equal base_58, Base58.binary_to_base58(Base58.base58_to_binary(base_58, alphabet), alphabet)
718
+ assert_equal binary, Base58.base58_to_binary(Base58.binary_to_base58(binary, alphabet), alphabet)
719
+ end
720
+ end
721
+ end
722
+
711
723
  def test_int_to_base58_all_alphabets
712
724
  EXAMPLES.each do |alphabet, examples|
713
725
  examples.each do |expected, integer|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: base58
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Douglas F Shearer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-08 00:00:00.000000000 Z
11
+ date: 2018-01-11 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Base58 is a Ruby library for converting ints or binaries to and from
14
14
  base58.