Package com.google.k2crypto.keyversions

Examples of com.google.k2crypto.keyversions.KeyVersionRegistry


  public Key(K2Context context, KeyData data)
      throws UnregisteredKeyVersionException, InvalidKeyDataException {
   
    // NOTE: lower-level exceptions take precedence by design
   
    KeyVersionRegistry registry = context.getKeyVersionRegistry();
    ExtensionRegistry protoRegistry = registry.getProtoExtensions();

    // Retain the core
    if (!data.hasCore()) {
      // Core field is required
      throw new InvalidKeyDataException(
          InvalidKeyDataException.Reason.PROTO_PARSE, null);
    }
    coreBytes = data.getCore();
   
    // Parse the core, containing the security/usage constraints
    KeyCore core;
    try {
      core = KeyCore.parseFrom(coreBytes, protoRegistry);
    } catch (InvalidProtocolBufferException ex) {
      throw new InvalidKeyDataException(
          InvalidKeyDataException.Reason.PROTO_PARSE, ex);
    }
    // TODO(darylseah): extract security properties from core

    // Extract the key version list
    final int kvCount = data.getKeyVersionCount();
    keyVersions.ensureCapacity(kvCount);

    UnregisteredKeyVersionException unregisteredException = null;
    InvalidKeyDataException buildException = null;
   
    for (KeyVersionData kvData : data.getKeyVersionList()) {
      if (!kvData.hasType()) {
        // Type field is required
        throw new InvalidKeyDataException(
            InvalidKeyDataException.Reason.PROTO_PARSE, null);
      }
      try {
        KeyVersion kv = registry.newBuilder(kvData.getType())
            .withData(kvData, protoRegistry).build();
        keyVersions.add(kv);
      } catch (InvalidProtocolBufferException ex) {
        // Throw proto parsing exceptions immediately
        throw new InvalidKeyDataException(
View Full Code Here


    // Initialize context and storage system
    K2Context context = new K2Context();
    K2Storage storage = new K2Storage(context);
   
    // Register available key versions
    KeyVersionRegistry registry = context.getKeyVersionRegistry();
    try {
      registry.register(AESKeyVersion.class);
      registry.register(HMACKeyVersion.class);
    } catch (KeyVersionException ex) {
      // Something wrong with a key version
      throw ex;
    }
   
View Full Code Here

  /**
   * Constructs a new K2 context.
   */
  public K2Context() {
    strings = new K2Strings(this, Locale.getDefault());
    keyVersionRegistry = new KeyVersionRegistry(this);
  }
View Full Code Here

TOP

Related Classes of com.google.k2crypto.keyversions.KeyVersionRegistry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.