Sha256: 2c2d4830dad40054b58f01a681dc14d0182f33ae55722cef7c55332b537246a2

Contents?: true

Size: 1.66 KB

Versions: 7

Compression:

Stored size: 1.66 KB

Contents

# -*- coding: binary -*-

module Rex
  module Proto
    module Kerberos
      module CredentialCache
        # This class provides a representation of a Principal stored in the Kerberos Credential Cache.
        class Principal < Element
          # @!attribute name_type
          #   @return [Fixnum]
          attr_accessor :name_type
          # @!attribute realm
          #   @return [String]
          attr_accessor :realm
          # @!attribute components
          #   @return [Array<String>]
          attr_accessor :components

          # Encodes the Rex::Proto::Kerberos::CredentialCache::Principal into an String
          #
          # @return [String] encoded principal
          def encode
            encoded = ''
            encoded << encode_name_type
            encoded << [components.length].pack('N')
            encoded << encode_realm
            encoded << encode_components

            encoded
          end

          private

          # Encodes the name_type field
          #
          # @return [String]
          def encode_name_type
            [name_type].pack('N')
          end

          # Encodes the realm field
          #
          # @return [String]
          def encode_realm
            encoded = ''
            encoded << [realm.length].pack('N')
            encoded << realm

            encoded
          end

          # Encodes the components field
          #
          # @return [String]
          def encode_components
            encoded = ''

            components.each do |c|
              encoded << [c.length].pack('N')
              encoded << c
            end

            encoded
          end

        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rex-2.0.13 lib/rex/proto/kerberos/credential_cache/principal.rb
rex-2.0.12 lib/rex/proto/kerberos/credential_cache/principal.rb
rex-2.0.11 lib/rex/proto/kerberos/credential_cache/principal.rb
rex-2.0.10 lib/rex/proto/kerberos/credential_cache/principal.rb
rex-2.0.9 lib/rex/proto/kerberos/credential_cache/principal.rb
rex-2.0.8 lib/rex/proto/kerberos/credential_cache/principal.rb
rex-2.0.7 lib/rex/proto/kerberos/credential_cache/principal.rb