public static DescriptorDigest fromHash(String hash) throws DigestException {
    if (!hash.matches(HASH_REGEX)) {
      throw new DigestException("Invalid hash: " + hash);
    }

    return new DescriptorDigest(hash);
  }
@Test
  public void testCreateFromHash_failIncorrectLength() {
    String badHash = createGoodHash('a') + 'a';

    try {
      DescriptorDigest.fromHash(badHash);
      Assert.fail("Invalid hash should have caused digest creation failure.");
    } catch (DigestException ex) {
      Assert.assertEquals("Invalid hash: " + badHash, ex.getMessage());
    }
  }