-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathspec_helper.rb
More file actions
40 lines (32 loc) · 1.16 KB
/
spec_helper.rb
File metadata and controls
40 lines (32 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require "ssh_data"
require "ed25519"
require "rspec-parameterized"
require "open3"
RSpec.configure do |config|
config.color_mode = :off
end
REPO_PATH = File.expand_path(File.join(__FILE__, "..", ".."))
FIXTURE_PATH = File.expand_path(File.join(REPO_PATH, "spec", "fixtures"))
def fixture(name, binary: false, pem: false)
data = File.read(File.join(FIXTURE_PATH, name))
return data unless binary
if pem
SSHData::Encoding.decode_pem(data, "OPENSSH PRIVATE KEY")
else
SSHData.key_parts(data)[1]
end
end
def ssh_keygen_fingerprint(name, algo, priv: false)
out, * = Open3.capture3("ssh-keygen #{'-e' if priv} -E #{algo} -l -f #{File.join(FIXTURE_PATH, name)}")
return nil if out.strip.empty?
out.split(":", 2).last.split(" ").first
end
def ec_private_to_public(private_key)
algorithm_identifier = OpenSSL::ASN1::Sequence.new([
OpenSSL::ASN1::ObjectId.new("id-ecPublicKey"),
OpenSSL::ASN1::ObjectId.new(private_key.group.curve_name)
])
subject_public_key = OpenSSL::ASN1::BitString.new(private_key.public_key.to_bn.to_s(2))
spki = OpenSSL::ASN1::Sequence.new([algorithm_identifier, subject_public_key])
OpenSSL::PKey::EC.new(spki.to_der)
end