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

Symmetric keygen: JsThemis #562

Merged
merged 5 commits into from
Dec 11, 2019

Commits on Dec 6, 2019

  1. Symmetric keygen: JsThemis

    Node.js native extensions and V8 are hard.
    
    Initially it was expected that JsThemis has an interface similar to
    WasmThemis. Something like this:
    
        class SymmetricKey extends Buffer {
            constructor(array) {
                if (array) {
                    super(array)
                } else {
                    super(generateNewKey())
                }
            }
        }
    
    Note SymmetricKey is a class which inherits from Buffer. Now consider
    the fact that JavaScript does not *really* have classes, it has objects,
    functions, and prototypes, with EcmaScript 6 classes being a nice syntax
    sugar on top of that.
    
    It turned out to be not obvious how to implement JavaScript inheritance
    from native JavaScript classes given the API provided by V8 (and I'm not
    even talking about the outstanding quality of V8 documentation /s).
    
    This is further complicated by the fact that all of the Buffer's
    constructors are considered deprecated, with Buffer.alloc() and
    Buffer.from() being the recommended way of constructing Buffers.
    
    I'm in a bit of a loss here so effectively SymmetricKey is now
    
        function SymmetricKey(array) {
            if (array) {
                return Buffer.from(array)
            } else {
                return generateKeyBuffer()
            }
        }
    
    This kinda works on the API level because classes are functions in
    JavaScript, but it's not strictly correct as "new SymmetricKey()"
    expression returns an instance of Buffer (not SymmetricKey). It's
    fine since that's all API that we need at the moment, but it's not
    clean. However, after spending around 4 hours trying to understand
    how to do inheritance, I kinda gave up.
    
    This should be enough for practical purposes for now. We will have
    to get back to this issue if we would like to provide our own wrapper
    over Buffer instances for all other keys, but for now it's good enough.
    
    *fingers crossed*
    ilammy committed Dec 6, 2019
    Configuration menu
    Copy the full SHA
    33115ec View commit details
    Browse the repository at this point in the history
  2. Stricter length tests

    ilammy committed Dec 6, 2019
    Configuration menu
    Copy the full SHA
    1341dc2 View commit details
    Browse the repository at this point in the history
  3. More empty buffer checks

    ilammy committed Dec 6, 2019
    Configuration menu
    Copy the full SHA
    919f283 View commit details
    Browse the repository at this point in the history
  4. More instance tests

    Let's make sure that we don't do anything silly in our Node.js extension
    code and don't accidentally reuse the same objects or memory buffers.
    ilammy committed Dec 6, 2019
    Configuration menu
    Copy the full SHA
    a248531 View commit details
    Browse the repository at this point in the history
  5. fixup! More instance tests

    JavaScript vOv Land of no compilation errors. (Though we could invest
    into a linter...)
    ilammy committed Dec 6, 2019
    Configuration menu
    Copy the full SHA
    364110f View commit details
    Browse the repository at this point in the history