Package com.google.k2crypto.storage

Examples of com.google.k2crypto.storage.IllegalAddressException


        this.keyIdentifier = keyIdentifier;
        return finalAddress;
      }
    } catch (SQLException ex) {
      // SQL-specific error
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.DRIVER_SPECIFIC, ex);
    } catch (IllegalArgumentException ex) {
      // The path is invalid (from URI.create or new File).
      // Fall-through for exception throw.
    }
   
    // Falling through to here implies the path is invalid
    throw new IllegalAddressException(address,
        IllegalAddressException.Reason.INVALID_PATH, null);
  }
View Full Code Here


   * @throws IllegalAddressException if the address has an invalid scheme.
   */
  private void checkScheme(URI address) throws IllegalAddressException {
    if (!SCHEME.equalsIgnoreCase(address.getScheme())) {
      // Unrecognized scheme
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.INVALID_SCHEME, null);
    }
  }
View Full Code Here

  private String extractKeyIdentifier(URI address)
      throws IllegalAddressException {
    final String keyIdentifier = extractFragment(address);
    if (!KEY_ID_REGEX.matcher(keyIdentifier).matches()) {
      // Fragment (specifying the key id) is invalid
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.INVALID_FRAGMENT, null);     
    }
    return keyIdentifier;
  }
View Full Code Here

    } else if (NATIVE_SCHEME.equalsIgnoreCase(scheme)) {
      // If the "k2" scheme is specified, the path need not have the extension.
      mustHaveExtension = false;
    } else {
      // Unrecognized scheme
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.INVALID_SCHEME, null);
    }
   
    // Extract path. We are assuming (below) that any encoded unreserved
    // characters have already been decoded by K2Storage.
    String path = extractRawPath(address);
   
    // Check if the file extension is included in the path.
    if (!EXTENSION_REGEX.matcher(path).find()) {
      if (mustHaveExtension) {
        throw new IllegalAddressException(
            address, IllegalAddressException.Reason.INVALID_PATH, null);
      }
      // Append if missing
      path = path + '.' + FILE_EXTENSION;
    }
   
    try {
      // Resolve the disk address of the provided path
      final URI diskAddress = new File("").toURI().resolve(path).normalize();
     
      // Create all file objects before checking
      final File pri = new File(diskAddress);
      final File parent = pri.getParentFile();
      final String filename = pri.getName();
      final File tmpA =
          new File(parent, TEMP_PREFIX + filename + TEMP_A_EXTENSION);
      final File tmpB =
          new File(parent, TEMP_PREFIX + filename + TEMP_B_EXTENSION);
     
      // Grab path from the file for checking and later usage
      path = pri.toURI().getRawPath();
     
      // Filename should be a valid
      if (FILENAME_REGEX.matcher(filename).matches()
          // Path should be absolute after normalization
          && !path.startsWith("/../")
          // Parent file should be an existing directory
          && parent != null && parent.isDirectory()
          // Everything else should NOT be a directory
          && !pri.isDirectory() && !tmpA.isDirectory() && !tmpB.isDirectory()) {
       
        // All OK. Generate final address with scheme and without extension.
        path = path.substring(0, path.length() - FILE_EXTENSION.length() - 1);
        URI finalAddress = URI.create(NATIVE_SCHEME + ':' + path);

        // Initialize the driver.
        this.keyFile = pri;
        this.tempFileA = tmpA;
        this.tempFileB = tmpB;
        return finalAddress;
      }
    } catch (IllegalArgumentException ex) {
      // The path is invalid (from URI.create or new File).
      // Fall-through for exception throw.
    }
   
    // Falling through to here implies the path is invalid
    throw new IllegalAddressException(address,
        IllegalAddressException.Reason.INVALID_PATH, null);
  }
View Full Code Here

   */
  private void checkScheme(URI address) throws IllegalAddressException {
    String scheme = address.getScheme();
    if (scheme != null && !NATIVE_SCHEME.equalsIgnoreCase(scheme)) {
      // Unrecognized scheme
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.INVALID_SCHEME, null);
    }
  }
View Full Code Here

   * @throws IllegalAddressException if the authority component exists.
   */
  public static void checkNoAuthority(URI address)
      throws IllegalAddressException {
    if (address.getAuthority() != null) {
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.AUTHORITY_UNSUPPORTED, null);
    }
  }
View Full Code Here

   */
  public static void checkNoUser(URI address)
      throws IllegalAddressException {
    String user = address.getUserInfo();
    if (user != null && user.length() > 0) {
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.USER_UNSUPPORTED, null);
    }
  }
View Full Code Here

   * @throws IllegalAddressException if the host or port component exists.
   */
  public static void checkNoHostPort(URI address)
      throws IllegalAddressException {
    if (address.getHost() != null || address.getPort() >= 0) {
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.HOST_PORT_UNSUPPORTED, null);
    }
  }
View Full Code Here

   */
  public static void checkNoPath(URI address)
      throws IllegalAddressException {
    String path = address.getPath();
    if (path != null && path.length() > 0) {
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.PATH_UNSUPPORTED, null);
    }
  }
View Full Code Here

   */
  public static void checkNoQuery(URI address)
      throws IllegalAddressException {
    String query = address.getQuery();
    if (query != null && query.length() > 0) {
      throw new IllegalAddressException(
          address, IllegalAddressException.Reason.QUERY_UNSUPPORTED, null);
    }
  }
View Full Code Here

TOP

Related Classes of com.google.k2crypto.storage.IllegalAddressException

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.