Skip to content

Commit 0b1f519

Browse files
committed
Rename hashalgorithm to hash_algorithm to match spec
1 parent d74f258 commit 0b1f519

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

lib/ssh_data/encoding.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ module Encoding
88
OPENSSH_SIGNATURE_VERSION = 0x01
99

1010
OPENSSH_SIGNATURE_FIELDS = [
11-
[:sigversion, :uint32],
12-
[:publickey, :string_public_key],
13-
[:namespace, :string],
14-
[:reserved, :string],
15-
[:hashalgorithm, :string],
16-
[:signature, :string],
11+
[:sigversion, :uint32],
12+
[:publickey, :string_public_key],
13+
[:namespace, :string],
14+
[:reserved, :string],
15+
[:hash_algorithm, :string],
16+
[:signature, :string],
1717
]
1818

1919
OPENSSH_PRIVATE_KEY_FIELDS = [

lib/ssh_data/signature.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Signature
2020
PublicKey::ALGO_RSA_SHA2_512,
2121
]
2222

23-
attr_reader :sigversion, :namespace, :signature, :reserved, :hashalgorithm
23+
attr_reader :sigversion, :namespace, :signature, :reserved, :hash_algorithm
2424

2525
# Parses a PEM armored SSH signature.
2626
# pem - A PEM encoded SSH signature.
@@ -47,13 +47,13 @@ def self.parse_blob(blob)
4747
new(**data)
4848
end
4949

50-
def initialize(sigversion:, publickey:, namespace:, reserved:, hashalgorithm:, signature:)
50+
def initialize(sigversion:, publickey:, namespace:, reserved:, hash_algorithm:, signature:)
5151
if sigversion > MAX_SUPPORTED_VERSION || sigversion < MIN_SUPPORTED_VERSION
5252
raise UnsupportedError, "Signature version is not supported"
5353
end
5454

55-
unless SUPPORTED_HASH_ALGORITHMS.has_key?(hashalgorithm)
56-
raise UnsupportedError, "Hash algorithm #{hashalgorithm} is not supported."
55+
unless SUPPORTED_HASH_ALGORITHMS.has_key?(hash_algorithm)
56+
raise UnsupportedError, "Hash algorithm #{hash_algorithm} is not supported."
5757
end
5858

5959
# Spec: empty namespaces are not permitted.
@@ -66,13 +66,13 @@ def initialize(sigversion:, publickey:, namespace:, reserved:, hashalgorithm:, s
6666
@publickey = publickey
6767
@namespace = namespace
6868
@reserved = reserved
69-
@hashalgorithm = hashalgorithm
69+
@hash_algorithm = hash_algorithm
7070
@signature = signature
7171
end
7272

7373
def verify(signed_data)
7474
key = public_key
75-
digest_algorithm = SUPPORTED_HASH_ALGORITHMS[@hashalgorithm]
75+
digest_algorithm = SUPPORTED_HASH_ALGORITHMS[@hash_algorithm]
7676

7777
if key.is_a?(PublicKey::RSA)
7878
sig_algo, * = Encoding.decode_signature(@signature)
@@ -85,14 +85,14 @@ def verify(signed_data)
8585
end
8686
end
8787

88-
raise AlgorithmError, "Unsupported digest algorithm #{@hashalgorithm}" if digest_algorithm.nil?
88+
raise AlgorithmError, "Unsupported digest algorithm #{@hash_algorithm}" if digest_algorithm.nil?
8989

9090
message_digest = digest_algorithm.digest(signed_data)
9191
blob =
9292
SIGNATURE_PREAMBLE +
9393
Encoding.encode_string(@namespace) +
9494
Encoding.encode_string(@reserved || "") +
95-
Encoding.encode_string(@hashalgorithm) +
95+
Encoding.encode_string(@hash_algorithm) +
9696
Encoding.encode_string(message_digest)
9797

9898
key.verify(blob, @signature)

spec/encoding_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@
823823
expect(data[:sigversion]).to eq(1)
824824
expect(data[:reserved]).to be_empty
825825
expect(data[:namespace]).to eq("file")
826-
expect(data[:hashalgorithm]).to eq("sha512")
826+
expect(data[:hash_algorithm]).to eq("sha512")
827827
expect(data[:signature]).not_to be_empty
828828
expect(data[:publickey]).not_to be_empty
829829
end

spec/signature_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
expect(subject.sigversion).to eq(1)
7373
expect(subject.namespace).to eq("file")
7474
expect(subject.reserved).to be_empty
75-
expect(subject.hashalgorithm).to eq("sha512")
75+
expect(subject.hash_algorithm).to eq("sha512")
7676
end
7777
end
7878
end

0 commit comments

Comments
 (0)