1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
# Manipulation of LDAP control data.
#
#--
# $Id: control.rb,v 1.2 2005/02/28 05:02:25 ianmacd Exp $
#++
#
# Copyright (C) 2004 Ian Macdonald <ian@caliban.org>
#
module LDAP
class Control
require 'openssl'
# Take +vals+, produce an Array of values in ASN.1 format and then
# convert the Array to DER.
#
def Control.encode( *vals )
encoded_vals = []
vals.each do |val|
encoded_vals <<
case val
when Integer
OpenSSL::ASN1::Integer( val )
when String
OpenSSL::ASN1::OctetString.new( val )
else
# What other types may exist?
end
end
OpenSSL::ASN1::Sequence.new( encoded_vals ).to_der
end
# Take an Array of ASN.1 data and return an Array of decoded values.
#
def decode
values = []
OpenSSL::ASN1::decode( self.value ).value.each do |val|
values << val.value
end
values
end
end
end
|