Class: SshTresor::AgentKey

Inherits:
Struct
  • Object
show all
Defined in:
lib/ssh_tresor/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#blobObject

Returns the value of attribute blob

Returns:

  • (Object)

    the current value of blob



11
12
13
# File 'lib/ssh_tresor/agent.rb', line 11

def blob
  @blob
end

#commentObject

Returns the value of attribute comment

Returns:

  • (Object)

    the current value of comment



11
12
13
# File 'lib/ssh_tresor/agent.rb', line 11

def comment
  @comment
end

Instance Method Details

#fingerprintObject



16
17
18
# File 'lib/ssh_tresor/agent.rb', line 16

def fingerprint
  "SHA256:#{Base64.strict_encode64(fingerprint_bytes).delete("=")}"
end

#fingerprint_bytesObject



12
13
14
# File 'lib/ssh_tresor/agent.rb', line 12

def fingerprint_bytes
  @fingerprint_bytes ||= Digest::SHA256.digest(blob)
end

#key_typeObject



28
29
30
# File 'lib/ssh_tresor/agent.rb', line 28

def key_type
  @key_type ||= Agent.format_key_type(blob)
end

#matches_fingerprint?(prefix) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
39
40
# File 'lib/ssh_tresor/agent.rb', line 36

def matches_fingerprint?(prefix)
  normalized_prefix = prefix.delete_prefix("SHA256:")
  normalized_fingerprint = fingerprint.delete_prefix("SHA256:")
  normalized_fingerprint.start_with?(normalized_prefix)
end

#md5_fingerprintObject



20
21
22
# File 'lib/ssh_tresor/agent.rb', line 20

def md5_fingerprint
  Digest::MD5.digest(blob).bytes.map { |byte| "%02x" % byte }.join(":")
end

#security_key?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/ssh_tresor/agent.rb', line 32

def security_key?
  ssh_type.start_with?("sk-")
end

#ssh_typeObject



24
25
26
# File 'lib/ssh_tresor/agent.rb', line 24

def ssh_type
  @ssh_type ||= SSHEncoding::Reader.new(blob).string
end

#to_sObject



42
43
44
# File 'lib/ssh_tresor/agent.rb', line 42

def to_s
  "#{fingerprint} #{key_type} #{comment}"
end