[ldns-users] Python rdf.data()

Karel Slany karel.slany at nic.cz
Tue Sep 10 15:18:08 UTC 2013

Hello Jack,

I apologise for the delay. I've added the functionality you wanted.
Currently it is only available in the git repository

The new rdf method is called data_as_bytearray() which returns a Python
bytearray containing a copy of the rdf data.

A simple usage example can be found in the attachment.

Best regards,

Am 28.08.2013 20:34, schrieb Jack Bates:
> Thank you Karel, I want to access certificate association data from a
> TLSA RR. From C I would use ldns_rdf_data() and ldns_rdf_size(), is that
> right? From Python, how do you use the return value from rdf.data()?
> The RDF is type HEX, so str(rdf) returns hex digits. I can convert them
> back to bytes, but rdf.data() and rdf.size() seemed like the more direct
> way to get the bytes?
> On 22/08/13 05:31 AM, Karel Slany wrote:
>> Greetings,
>> Python's ldns_rdf.data() creates a thin wrapper around the ldns C
>> function ldns_rdf_data(). Function ldns_rdf_data() returns a pointer to
>> an internal data field of the manipulated rdf.
>> Actually, I don't know the actual reason why you are trying to access
>> this low level structures. Manipulating them from Python can be tricky
>> as you can easily end up with corrupted memory.
>> In order to meet your desire I can add a new method ldns_rdf.data_str()
>> which would return a Python string containing copy of the rdf data
>> field. However, in Python3 this would be error-prone, because Python3
>> uses unicode strings. At the moment I cannot guess, whether the approach
>> would be reliabe in Python3.
>> Please give more information about the reason why you want to use
>> ldns_rdf.data(). Perhaps we could think of a more convenient solution.
>> K.
>> Am 22.08.2013 10:56, schrieb Willem Toorop:
>>> Hi Jack,
>>> I suspect raw access is not supported by pyldns.
>>> Karel, could shed some light on this?
>>> -- Willem
>>> Op 22-08-13 01:13, Jack Bates schreef:
>>>> I am working with the Python wrapper for ldns.
>>>> rdf.data() returns something like
>>>> <Swig Object of type 'uint8_t *' at 0xb742f938>
>>>> and rdf.size() returns the number of bytes. How do I read the bytes?
>>>> Thanks!
>>>> _______________________________________________
>>>> ldns-users mailing list
>>>> ldns-users at open.nlnetlabs.nl
>>>> http://open.nlnetlabs.nl/mailman/listinfo/ldns-users
>>> _______________________________________________
>>> ldns-users mailing list
>>> ldns-users at open.nlnetlabs.nl
>>> http://open.nlnetlabs.nl/mailman/listinfo/ldns-users

-------------- next part --------------
A non-text attachment was scrubbed...
Name: test_bytearray.py
Type: text/x-python
Size: 544 bytes
Desc: not available
URL: <http://lists.nlnetlabs.nl/pipermail/ldns-users/attachments/20130910/b80acb62/attachment.py>

More information about the ldns-users mailing list