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

Introduce common IKey interface #564

Merged
merged 2 commits into from
Dec 11, 2019

Commits on Dec 6, 2019

  1. Introduce common IKey interface

    Currently JavaThemis deals only with asymmetric keys and thus has
    an "AsymmetricKey" class providing common implementation of storage and
    utilities for PrivateKey and PublicKey classes. However, we are going to
    introduce a new type of keys -- "SymmetricKey" -- which will need these
    utilities as well. Since it's not an AsymmetricKey, let's refactor our
    class hierarchy a bit.
    
    Extract declaration of the "toByteArray()" utility method into a new
    interface "IKey". This interface will be implemented by all key classes
    of Themis and will provide common utilities. (E.g., base64 formatting
    may be added here in the future.)
    
    Extract storage implementation into a new "KeyBytes" class. It is an
    abstract package-private class, intended to be a base class for all
    keys implemented by Themis. It provides "key" field to access key bytes
    directly and implements IKey interface. It also maintains the invariant
    that all valid keys must be non-null and not empty.
    
    AsymmetricKey is left as a marker abstract class. It inherits storage
    and IKey implementation from KeyBytes. Plus, it still hosts the
    constants for asymmetric key types.
    ilammy committed Dec 6, 2019
    Configuration menu
    Copy the full SHA
    a3487c9 View commit details
    Browse the repository at this point in the history
  2. Copy key bytes on input as well

    KeyBytes keeps a copy of the original byte[] array and copies it again
    in toByteArray() implementation. This is because Java arrays are always
    mutable that we have to copy them in order to be sure that the user can
    never modify the data stored in KeyBytes.
    ilammy committed Dec 6, 2019
    Configuration menu
    Copy the full SHA
    ebf57b9 View commit details
    Browse the repository at this point in the history