On occasions it is very useful to either extract a TLV structure or create a TLV structure independend of the tag (not in the least in the asn lib itself).
This is also very useful in handeling sequences of implicit types.
I therefore would find it useful if two procedures are added:
proc ::asn::asnGetTLV { data_var tlv_var } {
# gets a tag/length/value structure from the start of the data.
# return false if data exhausted, true if data left
upvar $data_var data $tlv_var tlv
asnGetByte data tag
asnGetLength data length
asnGetBytes data $length temp
set tlv [asnTLV $tag $temp]
if {[string length $data] > 0} {
return true
} {
return false
}
}
proc ::asn::asnTLV {tag value} {
set len [string length $value]
return [binary format H2a*a$len [format %02X $tag] [asnLength $len] $value]
}
Logged In: YES
user_id=1463011
Originator: YES
Actually using it in http://wiki.tcl.tk/16631 suggest that for the asnTLV proc the following semantics are more useful:
proc asnGetTLV { data_var tlv_var } {
# gets a tag/length/value from the start of the data.
# return false if no data available, true if succesful
upvar $data_var data $tlv_var tlv
dputs "Getting the first element from: [util::string2hex $data]"
if {[string length $data] < 2} {
return false
}
asnGetByte data tag
asnGetLength data length
asnGetBytes data $length temp
set tlv [asnTLV $tag $temp]
return true
}