Convert binary to UUID from LDAP

2023-03-27 Thread Alexander Zhirov via Digitalmars-d-learn
I get `objectGUID` data from LDAP as binary data. I need to convert `ubyte[]` data into a readable `UUID`. As far as I understand, it is possible to do this via `toHexString()`, but I have reached a dead end. Is there a way to make it more elegant, like [this technique](https://dlang.org/phobo

Re: Convert binary to UUID from LDAP

2023-03-27 Thread novice2 via Digitalmars-d-learn
On Monday, 27 March 2023 at 17:56:22 UTC, Alexander Zhirov wrote: I get `objectGUID` data from LDAP as binary data. I need to convert `ubyte[]` data into a readable `UUID`. As far as I understand, it is possible to do this via `toHexString()`, but I have reached a dead end. Is there a way to ma

Re: Convert binary to UUID from LDAP

2023-03-27 Thread Alexander Zhirov via Digitalmars-d-learn
On Monday, 27 March 2023 at 18:33:46 UTC, novice2 wrote: https://run.dlang.io/is/JP01aZ ``` void main(){ import std.stdio: writeln; import std.format: format; ubyte[] a = [159, 199, 22, 163, 13, 74, 145, 73, 158, 112, 7, 192, 12, 193, 7, 194]; string b =

Re: Convert binary to UUID from LDAP

2023-03-27 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/27/23 1:56 PM, Alexander Zhirov wrote: I get `objectGUID` data from LDAP as binary data. I need to convert `ubyte[]` data into a readable `UUID`. As far as I understand, it is possible to do this via `toHexString()`, but I have reached a dead end. Is there a way to make it more elegant, li

Re: Convert binary to UUID from LDAP

2023-03-27 Thread Alexander Zhirov via Digitalmars-d-learn
On Tuesday, 28 March 2023 at 00:51:43 UTC, Steven Schveighoffer wrote: auto uuid = UUID(*cast(ubyte[16]*)youruuiddata.ptr); ```d ubyte[] arr = cast(ubyte[])value.attributes["objectGUID"][0].dup; writeln(UUID(cast(ubyte[16])arr.ptr)); ``` `Error: cannot cast expression 'cast(ubyte*)arr' of type

Re: Convert binary to UUID from LDAP

2023-03-27 Thread Alexander Zhirov via Digitalmars-d-learn
On Monday, 27 March 2023 at 18:39:19 UTC, Alexander Zhirov wrote: I mean get the UUID data type itself. Just using [this example](https://dlang.org/phobos/std_uuid.html#.UUID) `cast(ubyte[16])ubyte[]` will not work, conversion error. ```d writeln(toHexString(cast(ubyte[])value.attributes["objec

Re: Convert binary to UUID from LDAP

2023-03-28 Thread Kagamin via Digitalmars-d-learn
This guid is (int,short,short,byte[8]) in little endian byte order. So if you want to convert it to big endian, you'll need to swap bytes in those int and two shorts. ``` ubyte[] guid=... int* g1=cast(int*)guid.ptr; *g1=bswap(*g1); ```

Re: Convert binary to UUID from LDAP

2023-03-28 Thread Alexander Zhirov via Digitalmars-d-learn
On Tuesday, 28 March 2023 at 05:26:08 UTC, Alexander Zhirov wrote: When converting to HEX, I get the string `121F4C264DED5E41A33F445B0A1CAE32`, in which some values are reversed. I found ways on the Internet to transform the permutation method into the desired result, but most likely it will b

Re: Convert binary to UUID from LDAP

2023-03-28 Thread Alexander Zhirov via Digitalmars-d-learn
On Tuesday, 28 March 2023 at 08:15:03 UTC, Alexander Zhirov wrote: So far it has been possible to convert like this The idea was borrowed from [here](https://elixirforum.com/t/using-active-directory-guid-with-ecto-uuid-field/15904).

Re: Convert binary to UUID from LDAP

2023-03-28 Thread Jacob Shtokolov via Digitalmars-d-learn
On Tuesday, 28 March 2023 at 05:05:58 UTC, Alexander Zhirov wrote: `Error: cannot cast expression 'cast(ubyte*)arr' of type 'ubyte*' to 'ubyte[16]'` Here is the working example: ```d import std.stdio; import std.uuid; void main() { ubyte[] arr = [159, 199, 22, 163, 13, 74, 145, 73, 158, 112,

Re: Convert binary to UUID from LDAP

2023-03-28 Thread WebFreak001 via Digitalmars-d-learn
On Tuesday, 28 March 2023 at 05:05:58 UTC, Alexander Zhirov wrote: On Tuesday, 28 March 2023 at 00:51:43 UTC, Steven Schveighoffer wrote: auto uuid = UUID(*cast(ubyte[16]*)youruuiddata.ptr); ```d ubyte[] arr = cast(ubyte[])value.attributes["objectGUID"][0].dup; writeln(UUID(cast(ubyte[16])ar

Re: Convert binary to UUID from LDAP

2023-03-28 Thread Kagamin via Digitalmars-d-learn
This guid is (int,short,short,byte[8]) in little endian byte order. So if you want to convert it to big endian, you'll need to swap bytes in those int and two shorts. ``` ubyte[] guid=... int* g1=cast(int*)guid.ptr; *g1=bswap(*g1); ```

Re: Convert binary to UUID from LDAP

2023-03-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/28/23 1:05 AM, Alexander Zhirov wrote: On Tuesday, 28 March 2023 at 00:51:43 UTC, Steven Schveighoffer wrote: `auto uuid = UUID(*cast(ubyte[16]*)youruuiddata.ptr);` (added quotes here) ```d ubyte[] arr = cast(ubyte[])value.attributes["objectGUID"][0].dup; writeln(UUID(cast(ubyte[16])arr.p

Re: Convert binary to UUID from LDAP

2023-03-28 Thread Steven Schveighoffer via Digitalmars-d-learn
On 3/28/23 6:36 AM, WebFreak001 wrote: the formatting messed up here. Try this code: ```d auto uuid = UUID(     (cast(const(ubyte)[]) value.attributes["objectGUID"][0])     [0 .. 16] ); ``` Nice, I didn't think this would work actually! -Steve

Re: Convert binary to UUID from LDAP

2023-03-28 Thread Alexander Zhirov via Digitalmars-d-learn
On Tuesday, 28 March 2023 at 13:18:59 UTC, Kagamin wrote: This guid is (int,short,short,byte[8]) in little endian byte order. So if you want to convert it to big endian, you'll need to swap bytes in those int and two shorts. ``` ubyte[] guid=... int* g1=cast(int*)guid.ptr; *g1=bswap(*g1); ```