CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/kerberos/model/last_request.rb
Views: 11766
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module Kerberos
6
module Model
7
# This class provides a representation of request time
8
class LastRequest < Element
9
10
# @!attribute type
11
# @return [Integer] The type of value
12
attr_accessor :type
13
# @!attribute value
14
# @return [Time] the time of the last request
15
attr_accessor :value
16
17
# Decodes a Rex::Proto::Kerberos::Model::LastRequest
18
#
19
# @param input [String, OpenSSL::ASN1::Sequence] the input to decode from
20
# @return [self] if decoding succeeds
21
# @raise [Rex::Proto::Kerberos::Model::Error::KerberosDecodingError] if decoding doesn't succeed
22
def decode(input)
23
case input
24
when String
25
decode_string(input)
26
when OpenSSL::ASN1::Sequence
27
decode_asn1(input)
28
else
29
raise ::Rex::Proto::Kerberos::Model::Error::KerberosDecodingError, 'Failed to decode LastRequest, invalid input'
30
end
31
32
self
33
end
34
35
# Rex::Proto::Kerberos::Model::LastRequest encoding isn't supported
36
#
37
# @raise [NotImplementedError]
38
def encode
39
raise ::NotImplementedError, 'LastRequest encoding not supported'
40
end
41
42
private
43
44
# Decodes a Rex::Proto::Kerberos::Model::LastReque from an String
45
#
46
# @param input [String] the input to decode from
47
def decode_string(input)
48
asn1 = OpenSSL::ASN1.decode(input)
49
50
decode_asn1(asn1)
51
end
52
53
# Decodes a Rex::Proto::Kerberos::Model::EncryptionKey from an
54
# OpenSSL::ASN1::Sequence
55
#
56
# @param input [OpenSSL::ASN1::Sequence] the input to decode from
57
def decode_asn1(input)
58
seq_values = input.value
59
self.type = decode_type(seq_values[0])
60
self.value = decode_value(seq_values[1])
61
end
62
63
# Decodes the key_type from an OpenSSL::ASN1::ASN1Data
64
#
65
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
66
# @return [Integer]
67
def decode_type(input)
68
input.value[0].value.to_i
69
end
70
71
# Decodes the value from an OpenSSL::ASN1::ASN1Data
72
#
73
# @param input [OpenSSL::ASN1::ASN1Data] the input to decode from
74
# @return [Time]
75
def decode_value(input)
76
input.value[0].value
77
end
78
end
79
end
80
end
81
end
82
end
83
84