public static DescriptorDigest fromDigest(String digest) throws DigestException {
    if (!digest.matches(DIGEST_REGEX)) {
      throw new DigestException("Invalid digest: " + digest);
    }

    // Extracts the hash portion of the digest.
    String hash = digest.substring(DIGEST_PREFIX.length());
    return new DescriptorDigest(hash);
  }
@Test
  public void testCreateFromDigest_fail() {
    String badDigest = "sha256:not a valid digest";

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