Class: EsuApi::Checksum

Inherits:
Object
  • Object
show all
Defined in:
lib/EsuApi.rb

Constant Summary collapse

SHA0 =
"SHA0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(algorithm) ⇒ Checksum

Returns a new instance of Checksum.



1040
1041
1042
1043
1044
1045
# File 'lib/EsuApi.rb', line 1040

def initialize( algorithm )
  @algorithm = algorithm
  @hash = EsuApi::SHA0.new();
  @offset = 0;
  @expected_value = ""
end

Instance Attribute Details

#expected_valueObject

Returns the value of attribute expected_value.



1062
1063
1064
# File 'lib/EsuApi.rb', line 1062

def expected_value
  @expected_value
end

Instance Method Details

#to_sObject



1052
1053
1054
1055
1056
1057
1058
1059
1060
# File 'lib/EsuApi.rb', line 1052

def to_s()
  value = @hash.clone().hashFinal(nil)
  
  hval = ""
  value.each_byte { |b|
    hval += "%.2x" % b
  }
  return "#{@algorithm}/#{@offset}/#{hval}"
end

#update(data) ⇒ Object



1047
1048
1049
1050
# File 'lib/EsuApi.rb', line 1047

def update( data )
   @offset += data.length()
   @hash.hashUpdate( data )
end