Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/main/java/land/oras/LayoutRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ public static LayoutRef parse(String name) {
return new LayoutRef(path, tag);
}

/**
* Return a new layout reference for a path
* @param path The path
* @return The layout ref
*/
public LayoutRef forPath(Path path) {
return new LayoutRef(path, tag);
}

/**
* Return a new layout reference for a path
* @param ociLayout The OCI layout
* @return The layout ref
*/
public LayoutRef forLayout(OCILayout ociLayout) {
return forPath(ociLayout.getPath());
}

@Override
public SupportedAlgorithm getAlgorithm() {
// Default if not set
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/land/oras/OCI.java
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ public Manifest attachArtifact(T ref, ArtifactType artifactType, Annotations ann
.withSubject(subject);
return pushManifest(
ref.withDigest(
SupportedAlgorithm.SHA256.digest(manifest.toJson().getBytes(StandardCharsets.UTF_8))),
SupportedAlgorithm.getDefault().digest(manifest.toJson().getBytes(StandardCharsets.UTF_8))),
manifest);
}
}
14 changes: 14 additions & 0 deletions src/test/java/land/oras/LayoutRefTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public class LayoutRefTest {
@TempDir
public static Path tempDir;

@TempDir
public static Path ociLayoutTempDir;

@TempDir
public static Path otherOciLayout;

@Test
void shouldParseLayoutWithAllParts() {
String ociLayout = tempDir.resolve("foo").toString();
Expand Down Expand Up @@ -62,6 +68,14 @@ void shouldParseFolderNameOnly() {
assertEquals("foo", layoutRef.getFolder().toString());
}

@Test
void shouldReturnForOciLayout() {
OCILayout ociLayout = OCILayout.builder().defaults(ociLayoutTempDir).build();
LayoutRef layoutRef =
LayoutRef.parse(otherOciLayout.getFileName().toString()).forLayout(ociLayout);
assertEquals(layoutRef.getFolder(), ociLayoutTempDir, "Path should be the same");
}

@Test
void shouldFailWithInvalidRef() {
assertThrows(OrasException.class, () -> LayoutRef.parse(""));
Expand Down