Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/kerberos/model/encryption_key.rb
Views: 11765
# -*- coding: binary -*-12module Rex3module Proto4module Kerberos5module Model6# This class provides a representation of a Kerberos EncryptionKey data7# definition8class EncryptionKey < Element910# @!attribute key11# @return [Integer] The type of encryption key12attr_accessor :type13# @!attribute value14# @return [String] the key itself15attr_accessor :value1617def ==(other)18type == other.type &&19value == other.value20end2122# Decodes a Rex::Proto::Kerberos::Model::EncryptionKey23#24# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from25# @return [self] if decoding succeeds26# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed27def decode(input)28case input29when String30decode_string(input)31when OpenSSL::ASN1::Sequence32decode_asn1(input)33else34raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode EncryptionKey, invalid input'35end3637self38end3940# Encodes a Rex::Proto::Kerberos::Model::EncryptionKey into an41# ASN.1 String42#43# @return [String]44def encode45elems = []46elems << OpenSSL::ASN1::ASN1Data.new([encode_type], 0, :CONTEXT_SPECIFIC)47elems << OpenSSL::ASN1::ASN1Data.new([encode_value], 1, :CONTEXT_SPECIFIC)48seq = OpenSSL::ASN1::Sequence.new(elems)4950seq.to_der51end5253private5455# Decodes a Rex::Proto::Kerberos::Model::EncryptionKey from an String56#57# @param input [String] the input to decode from58def decode_string(input)59asn1 = OpenSSL::ASN1.decode(input)6061decode_asn1(asn1)62end6364# Decodes a Rex::Proto::Kerberos::Model::EncryptionKey from an65# OpenSSL::ASN1::Sequence66#67# @param input [OpenSSL::ASN1::Sequence] the input to decode from68def decode_asn1(input)69seq_values = input.value70self.type = decode_type(seq_values[0])71self.value = decode_value(seq_values[1])72end7374# Decodes the type from an OpenSSL::ASN1::ASN1Data75#76# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from77# @return [Integer]78def decode_type(input)79input.value[0].value.to_i80end8182# Decodes the value from an OpenSSL::ASN1::ASN1Data83#84# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from85# @return [String]86def decode_value(input)87input.value[0].value88end8990# Encodes the type field91#92# @return [OpenSSL::ASN1::Integer]93def encode_type94bn = OpenSSL::BN.new(type.to_s)95int = OpenSSL::ASN1::Integer.new(bn)9697int98end99100# Encodes the value field101#102# @return [OpenSSL::ASN1::OctetString]103def encode_value104OpenSSL::ASN1::OctetString.new(value)105end106end107end108end109end110end111112113