Sha256: 4a7450cc3fb3b54b0696ddd1a1e649904ac75d915e4ccf1a2d3ef6923508122d
Contents?: true
Size: 1.43 KB
Versions: 1
Compression:
Stored size: 1.43 KB
Contents
module Net class LDAP module Extensions module Fixnum # # to_ber # def to_ber "\002" + to_ber_internal end # # to_ber_enumerated # def to_ber_enumerated "\012" + to_ber_internal end # # to_ber_length_encoding # def to_ber_length_encoding if self <= 127 [self].pack('C') else i = [self].pack('N').sub(/^[\0]+/,"") [0x80 + i.length].pack('C') + i end end # Generate a BER-encoding for an application-defined INTEGER. # Example: SNMP's Counter, Gauge, and TimeTick types. # def to_ber_application tag [0x40 + tag].pack("C") + to_ber_internal end #-- # Called internally to BER-encode the length and content bytes of a Fixnum. # The caller will prepend the tag byte. MAX_SIZE = 0.size def to_ber_internal size = MAX_SIZE while size>1 break if (self & (0xff << (size-1)*8)) > 0 size -= 1 end result = [size] while size>0 # right shift size-1 bytes, mask with 0xff result << ((self >> ((size-1)*8)) & 0xff) size -= 1 end result.pack('C*') end private :to_ber_internal end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
net-ldap-0.1.0 | lib/net/ldap/core_ext/fixnum.rb |