Hydroper
Hydroper

Reputation: 433

Issue setting domain memory

I'm testing decoding base-64 data, reading it efficiently through ApplicationDomain#domainMemory, inside a background worker:

override public function decode(): Array {
    ...
    ApplicationDomain.currentDomain.domainMemory = task.input;
    ...
}

I've noticed that I'm receiving an "End of file" error exactly from that assignment to domainMemory with a task.input of 16 bytes that has been received from the main worker.

Error #1504: End of file.

I've tested my similiar encode() function and it produces no such error.

MCVE

Run https://github.com/agera-air/org.agera.crypto by running the script run/test with the following requirements:

package {
    import flash.display.Sprite;
    import org.agera.crypto.*;
    import org.agera.util.*;

    public class Main extends Sprite {
        public function Main() {
            encrypt("Some string", EncryptionFormat.BASE_64)
                .then(function(data: String): void {
                    assertEquals(data, "U29tZSBzdHJpbmc=");
                    trace("Base-64 encryption .. OK");
                })
                .otherwise(function(error: Error): void {
                    trace("Base-64 encryption .. ERROR");
                });
            decrypt("U29tZSBzdHJpbmc=", EncryptionFormat.BASE_64)
                .then(function(data: String): void {
                    assertEquals(data, "Some string");
                    trace("Base-64 decryption .. OK");
                })
                .otherwise(function(error: Error): void {
                    trace(error.message);
                    trace("Base-64 decryption .. ERROR");
                });
        }
    }
}

Upvotes: 1

Views: 58

Answers (1)

Hydroper
Hydroper

Reputation: 433

The problem was a minor typo in my code when copying algorithm codes from the by.blooddy.crypto cryptography library:

In packages/org.agera.crypto.worker/src/org/agera/crypto/worker/formats/Base64.as, changed from

override public function decode(): Array {
    ...
    if (memory.length < ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) {
        memory.length = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;
    }

    ApplicationDomain.currentDomain.domainMemory = task.input;
    ...
}

to...

override public function decode(): Array {
    ...
    if (memory.length < ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH) {
        memory.length = ApplicationDomain.MIN_DOMAIN_MEMORY_LENGTH;
    }

    ApplicationDomain.currentDomain.domainMemory = memory;
    ...
}

Upvotes: 1

Related Questions