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

Edit list not applied according to specification #89

Open
lyytinen opened this issue Oct 19, 2023 · 0 comments
Open

Edit list not applied according to specification #89

lyytinen opened this issue Oct 19, 2023 · 0 comments
Assignees

Comments

@lyytinen
Copy link
Contributor

lyytinen commented Oct 19, 2023

Describe the bug

Section 4.2 of the specification outlines how the edit list is applied. In the example, it says that the last keep value "[...] could actually be left out as it extends all the way to the end of the file." While testing my PR #88, I noticed that the last keep value is not optional in this implementation. Is this a potential interoperability issue?

To Reproduce

Encrypt value "1234" with edit list [3].

Expected behavior

Expecting first 3 bytes to be discarded. Decrypted result should therefore be "4".

Actual behavior

All data is discarded resulting to an empty result. Changing the edit list to [3,1] produces the expected result "4".

Sample code

    @Test
    public void testEditListImplementation() throws Exception {
        PrivateKey writerPrivateKey = keyUtils.generatePrivateKey();
        KeyPair readerKeyPair = keyUtils.generateKeyPair();
        PrivateKey readerPrivateKey = readerKeyPair.getPrivate();
        PublicKey readerPublicKey = readerKeyPair.getPublic();

        try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
            try (Crypt4GHOutputStream crypt4GHOutputStream = new Crypt4GHOutputStream(byteArrayOutputStream, new DataEditList(new long[]{ 3 }), writerPrivateKey, readerPublicKey)) {
                crypt4GHOutputStream.write("1234".getBytes());
            }
            try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
                 Crypt4GHInputStream crypt4GHInputStream = new Crypt4GHInputStream(byteArrayInputStream, readerPrivateKey)) {

                Assert.assertArrayEquals("4".getBytes(), crypt4GHInputStream.readAllBytes()); // Fails!
            }
        }
    }
@kjetilkl kjetilkl self-assigned this Oct 23, 2023
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