Use URL SAFE base 64
This commit is contained in:
parent
959bf8c4fd
commit
86eff67b0d
|
@ -21,12 +21,12 @@ module Pigeon
|
|||
end
|
||||
|
||||
def private_key
|
||||
@private_key ||= Base64.strict_encode64(@seed)
|
||||
@private_key ||= Base64.urlsafe_encode64(@seed)
|
||||
end
|
||||
|
||||
def public_key
|
||||
bytes = @raw_key.verify_key.to_bytes
|
||||
b64 = Base64.strict_encode64(bytes)
|
||||
b64 = Base64.urlsafe_encode64(bytes)
|
||||
|
||||
@public_key ||= [HEADER, b64, FOOTER].join("")
|
||||
end
|
||||
|
|
|
@ -7,7 +7,7 @@ module Pigeon
|
|||
CONF_DIR = "conf"
|
||||
BLOB_DIR = "blobs"
|
||||
PEER_DIR = "peers"
|
||||
BLOCK_DIR = "__blocked__"
|
||||
BLOCK_DIR = "blocked"
|
||||
|
||||
BLOB_HEADER = "&"
|
||||
BLOB_FOOTER = ".sha256"
|
||||
|
@ -55,31 +55,28 @@ module Pigeon
|
|||
# Imagine: A "/" in a file name. Bad.
|
||||
# We will use base36 for files operations
|
||||
# instead.
|
||||
def to_base36(identity)
|
||||
identity
|
||||
def urlsafe_base64(identity)
|
||||
Base64.urlsafe_decode64(identity
|
||||
.gsub("@", "")
|
||||
.gsub(".ed25519", "")
|
||||
.each_byte
|
||||
.map { |b| b.to_s(36) }
|
||||
.join
|
||||
.gsub(".ed25519", ""))
|
||||
end
|
||||
|
||||
def from_base36(identity)
|
||||
end
|
||||
|
||||
def add_peer(identity)
|
||||
path = to_base36(identity)
|
||||
path = urlsafe_base64(identity)
|
||||
FileUtils.mkdir_p(File.join(peer_dir, path))
|
||||
end
|
||||
|
||||
def remove_peer(identity)
|
||||
path = to_base36(identity)
|
||||
path = urlsafe_base64(identity)
|
||||
FileUtils.rm_rf(path)
|
||||
end
|
||||
|
||||
def block_peer(identity)
|
||||
remove_peer(identity)
|
||||
path = to_base36(identity)
|
||||
path = urlsafe_base64(identity)
|
||||
FileUtils.touch(File.join(block_dir, path))
|
||||
end
|
||||
|
||||
|
@ -109,7 +106,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def block_dir
|
||||
File.join(peer_dir, BLOCK_DIR)
|
||||
File.join(ROOT_DIR, BLOCK_DIR)
|
||||
end
|
||||
|
||||
def blob_path_for(hex_hash_string)
|
||||
|
|
|
@ -8,9 +8,9 @@ RSpec.describe Pigeon::KeyPair do
|
|||
let(:kp) { Pigeon::KeyPair.new(FAKE_SEED) }
|
||||
|
||||
it "generates a pair from a seed" do
|
||||
x = "@7n/g0ca9FFWvMkXy2TMwM7bdMn6tNiEHKzrFX+CzAmQ=.ed25519"
|
||||
x = "@7n_g0ca9FFWvMkXy2TMwM7bdMn6tNiEHKzrFX-CzAmQ=.ed25519"
|
||||
expect(kp.public_key).to eq(x)
|
||||
y = "FbGoHeEcePDG3Evemrc+hm+S77cXKf8BRQgkYinJggg="
|
||||
y = "FbGoHeEcePDG3Evemrc-hm-S77cXKf8BRQgkYinJggg="
|
||||
expect(kp.private_key).to eq(y)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue