metasploit-framework/lib/rex/proto/kerberos/model/encryption_key.rb

79 lines
2.3 KiB
Ruby

# -*- coding: binary -*-
module Rex
module Proto
module Kerberos
module Model
# This class provides a representation of an Encryption Key
class EncryptionKey < Element
# @!attribute key
# @return [Fixnum] The type of encryption key
attr_accessor :type
# @!attribute value
# @return [String] the key itself
attr_accessor :value
# Decodes a Rex::Proto::Kerberos::Model::EncryptionKey
#
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
# @return [self] if decoding succeeds
# @raise [RuntimeError] if decoding doesn't succeed
def decode(input)
case input
when String
decode_string(input)
when OpenSSL::ASN1::Sequence
decode_asn1(input)
else
raise ::RuntimeError, 'Failed to decode Encryption Key, invalid input'
end
self
end
def encode
raise ::RuntimeError, 'EncryptionKey encoding not supported'
end
private
# Decodes a Rex::Proto::Kerberos::Model::EncryptionKey from an String
#
# @param input [String] the input to decode from
def decode_string(input)
asn1 = OpenSSL::ASN1.decode(input)
decode_asn1(asn1)
end
# Decodes a Rex::Proto::Kerberos::Model::EncryptionKey from an
# OpenSSL::ASN1::Sequence
#
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
def decode_asn1(input)
seq_values = input.value
self.type = decode_type(seq_values[0])
self.value = decode_value(seq_values[1])
end
# Decodes the type from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [Fixnum]
def decode_type(input)
input.value[0].value.to_i
end
# Decodes the value from an OpenSSL::ASN1::ASN1Data
#
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
# @return [String]
def decode_value(input)
input.value[0].value
end
end
end
end
end
end