metasploit-framework/lib/rex/proto/kerberos/credential_cache/principal.rb

71 lines
1.7 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
2014-12-18 05:16:58 +00:00
module Rex
module Proto
module Kerberos
module CredentialCache
# This class provides a representation of a Principal stored in the Kerberos Credential Cache.
2014-12-18 06:30:47 +00:00
class Principal < Element
# @!attribute name_type
# @return [Fixnum]
2014-12-18 06:30:47 +00:00
attr_accessor :name_type
# @!attribute realm
# @return [String]
2014-12-18 06:30:47 +00:00
attr_accessor :realm
# @!attribute components
# @return [Array<String>]
2014-12-18 06:30:47 +00:00
attr_accessor :components
# Encodes the Rex::Proto::Kerberos::CredentialCache::Principal into an String
#
# @return [String] encoded principal
2014-12-18 06:30:47 +00:00
def encode
encoded = ''
encoded << encode_name_type
encoded << [components.length].pack('N')
2014-12-18 06:30:47 +00:00
encoded << encode_realm
encoded << encode_components
encoded
end
private
# Encodes the name_type field
#
# @return [String]
2014-12-18 06:30:47 +00:00
def encode_name_type
[name_type].pack('N')
2014-12-18 06:30:47 +00:00
end
# Encodes the realm field
#
# @return [String]
2014-12-18 06:30:47 +00:00
def encode_realm
encoded = ''
encoded << [realm.length].pack('N')
2014-12-18 06:30:47 +00:00
encoded << realm
encoded
2014-12-18 06:30:47 +00:00
end
# Encodes the components field
#
# @return [String]
2014-12-18 06:30:47 +00:00
def encode_components
encoded = ''
components.each do |c|
encoded << [c.length].pack('N')
2014-12-18 06:30:47 +00:00
encoded << c
end
encoded
end
2014-12-18 05:16:58 +00:00
end
end
end
end
end