class Rex::Proto::Kerberos::Model::EncryptionKey
This class provides a representation of a Kerberos
EncryptionKey
data definition
Attributes
@!attribute key
@return [Fixnum] The type of encryption key
@!attribute value
@return [String] the key itself
Public Instance Methods
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
# File lib/rex/proto/kerberos/model/encryption_key.rb, line 22 def decode(input) case input when String decode_string(input) when OpenSSL::ASN1::Sequence decode_asn1(input) else raise ::RuntimeError, 'Failed to decode EncryptionKey, invalid input' end self end
Encodes a Rex::Proto::Kerberos::Model::EncryptionKey
into an ASN.1 String
@return [String]
# File lib/rex/proto/kerberos/model/encryption_key.rb, line 39 def encode elems = [] elems << OpenSSL::ASN1::ASN1Data.new([encode_type], 0, :CONTEXT_SPECIFIC) elems << OpenSSL::ASN1::ASN1Data.new([encode_value], 1, :CONTEXT_SPECIFIC) seq = OpenSSL::ASN1::Sequence.new(elems) seq.to_der end
Private Instance Methods
Decodes a Rex::Proto::Kerberos::Model::EncryptionKey
from an OpenSSL::ASN1::Sequence
@param input [OpenSSL::ASN1::Sequence] the input to decode from
# File lib/rex/proto/kerberos/model/encryption_key.rb, line 63 def decode_asn1(input) seq_values = input.value self.type = decode_type(seq_values[0]) self.value = decode_value(seq_values[1]) end
Decodes a Rex::Proto::Kerberos::Model::EncryptionKey
from an String
@param input [String] the input to decode from
# File lib/rex/proto/kerberos/model/encryption_key.rb, line 53 def decode_string(input) asn1 = OpenSSL::ASN1.decode(input) decode_asn1(asn1) end
Decodes the type from an OpenSSL::ASN1::ASN1Data
@param input [OpenSSL::ASN1::ASN1Data] the input to decode from @return [Fixnum]
# File lib/rex/proto/kerberos/model/encryption_key.rb, line 73 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]
# File lib/rex/proto/kerberos/model/encryption_key.rb, line 81 def decode_value(input) input.value[0].value end
Encodes the type field
@return [OpenSSL::ASN1::Integer]
# File lib/rex/proto/kerberos/model/encryption_key.rb, line 88 def encode_type bn = OpenSSL::BN.new(type.to_s) int = OpenSSL::ASN1::Integer.new(bn) int end
Encodes the value field
@return [OpenSSL::ASN1::OctetString]
# File lib/rex/proto/kerberos/model/encryption_key.rb, line 98 def encode_value OpenSSL::ASN1::OctetString.new(value) end