Class: KRB5::Principal

Inherits:
Object
  • Object
show all
Includes:
Mixin::Packer
Defined in:
lib/krb5/principal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Packer

#pack_bytes, #pack_int16, #pack_int32, #pack_int8

Constructor Details

#initialize(keytab) ⇒ Principal

Returns a new instance of Principal.



16
17
18
19
# File 'lib/krb5/principal.rb', line 16

def initialize(keytab)
  @keytab = keytab
  @components = []
end

Instance Attribute Details

#bytesSting?

Place to store byte array for #to_bytes

Returns:

  • (Sting, nil)


14
15
16
# File 'lib/krb5/principal.rb', line 14

def bytes
  @bytes
end

#componentsObject

Returns the value of attribute components.



10
11
12
# File 'lib/krb5/principal.rb', line 10

def components
  @components
end

#keytabKRB5::Keytab

Returns:



8
9
10
# File 'lib/krb5/principal.rb', line 8

def keytab
  @keytab
end

#name_typeObject

Returns the value of attribute name_type.



10
11
12
# File 'lib/krb5/principal.rb', line 10

def name_type
  @name_type
end

#realmObject

Returns the value of attribute realm.



10
11
12
# File 'lib/krb5/principal.rb', line 10

def realm
  @realm
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/krb5/principal.rb', line 54

def ==(other)
  i[realm components name_type].each do |state|
    return false unless other.send(state) == self.send(state)
  end

  true
end

#pack_count_of_componentsObject



45
46
47
48
49
50
51
52
# File 'lib/krb5/principal.rb', line 45

def pack_count_of_components
  if keytab.version == 1
    # Component length includes realm in v1 Keytabs
    pack_int16(components.length + 1)
  elsif keytab.version == 2
    pack_int16(components.length)
  end
end

#to_bytesObject

principal ::=

count of components (16 bits) [includes realm in version 1]
realm (data)
component1 (data)
component2 (data)
...
name type (32 bits) [omitted in version 1]


32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/krb5/principal.rb', line 32

def to_bytes
  pack_count_of_components
  pack_int16(realm.length)
  pack_bytes(realm)
  components.each do |component|
    pack_int16(component.length)
    pack_bytes(component)
  end
  pack_int32(name_type)

  @bytes.join
end

#to_sObject



21
22
23
# File 'lib/krb5/principal.rb', line 21

def to_s
  components.join('/') + "@" + realm
end