Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default UUID to byte array converter with little endian support #635

Open
goto1134 opened this issue Apr 10, 2022 · 1 comment
Open
Milestone

Comments

@goto1134
Copy link

goto1134 commented Apr 10, 2022

Since all binary data is stored in little endian format in ldap, it is not very obvious that the following objectGUID 90d1c68e-01be-4485-aafd-b3ffb9ddb026 should be converted to an octet string \8e\c6\d1\90\be\01\85\44\aa\fd\b3\ff\b9\dd\b0\26.

Please, provide the default converters for byte[] <-> java.util.UUID transformations. Here are some of my ideas for these converters:

@Component
class ByteArrayToUuidConverter : Converter<ByteArray, UUID> {
    override fun convert(guidBytes: ByteArray): UUID {
        require(guidBytes.size == 16) {
            "Guid bytes must be 16 byte long, but was ${guidBytes.size}"
        }
        val bytes = guidBytes.copyOf().apply {
            reverse(0, 4)
            reverse(4, 6)
            reverse(6, 8)
        }
        return ByteBuffer.wrap(bytes).let { UUID(it.long, it.long) }
    }
}

@Component
class UuidToByteArrayConverter : Converter<UUID, ByteArray> {
    override fun convert(source: UUID): ByteArray {
        val byteBuffer = ByteBuffer.wrap(ByteArray(16)).apply {
            putLong(source.mostSignificantBits)
            putLong(source.leastSignificantBits)
        }
        val guidBytes = byteBuffer.array().apply {
            reverse(0, 4)
            reverse(4, 6)
            reverse(6, 8)
        }
        return guidBytes
    }
}
@goto1134
Copy link
Author

This issue is also related to #633

@jzheaux jzheaux added this to the 3.3.x milestone Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants