Search in sources :

Example 1 with MD5

use of aQute.libg.cryptography.MD5 in project bnd by bndtools.

the class MavenFileRepository method store.

@Override
public void store(File source, String path) throws Exception {
    if (!source.isFile())
        throw new IllegalArgumentException("File does not exist: " + source);
    File dest = getFile(path);
    IO.mkdirs(dest.getParentFile());
    IO.copy(source, dest);
    SHA1 sha1 = SHA1.digest(source);
    MD5 md5 = MD5.digest(source);
    IO.store(sha1.asHex() + "\n", new File(dest.getParentFile(), dest.getName() + ".sha1"));
    IO.store(md5.asHex() + "\n", new File(dest.getParentFile(), dest.getName() + ".md5"));
}
Also used : SHA1(aQute.libg.cryptography.SHA1) File(java.io.File) MD5(aQute.libg.cryptography.MD5)

Example 2 with MD5

use of aQute.libg.cryptography.MD5 in project bnd by bndtools.

the class MavenRemoteRepository method store.

public void store(File file, String path) throws Exception {
    int n = 0;
    URL url = new URL(base + path);
    SHA1 sha1 = SHA1.digest(file);
    MD5 md5 = MD5.digest(file);
    try (TaggedData go = client.build().put().upload(file).updateTag().asTag().go(url)) {
        switch(go.getState()) {
            case NOT_FOUND:
            case OTHER:
                throw new IOException("Could not store " + path + " from " + file + " with " + go);
            case UNMODIFIED:
            case UPDATED:
            default:
                break;
        }
    }
    try (TaggedData tag = client.build().put().upload(sha1.asHex()).asTag().go(new URL(base + path + ".sha1"))) {
    }
    try (TaggedData tag = client.build().put().upload(md5.asHex()).asTag().go(new URL(base + path + ".md5"))) {
    }
}
Also used : SHA1(aQute.libg.cryptography.SHA1) TaggedData(aQute.bnd.service.url.TaggedData) IOException(java.io.IOException) URL(java.net.URL) MD5(aQute.libg.cryptography.MD5)

Example 3 with MD5

use of aQute.libg.cryptography.MD5 in project bnd by bndtools.

the class Analyzer method _md5.

public String _md5(String[] args) throws Exception {
    Macro.verifyCommand(args, _md5Help, new Pattern[] { null, null, Pattern.compile("base64|hex") }, 2, 3);
    Digester<MD5> digester = MD5.getDigester();
    Resource r = dot.getResource(args[1]);
    if (r == null)
        throw new FileNotFoundException("From " + digester + ", not found " + args[1]);
    IO.copy(r.openInputStream(), digester);
    boolean hex = args.length > 2 && args[2].equals("hex");
    if (hex)
        return Hex.toHexString(digester.digest().digest());
    return Base64.encodeBase64(digester.digest().digest());
}
Also used : FileNotFoundException(java.io.FileNotFoundException) MD5(aQute.libg.cryptography.MD5)

Aggregations

MD5 (aQute.libg.cryptography.MD5)3 SHA1 (aQute.libg.cryptography.SHA1)2 TaggedData (aQute.bnd.service.url.TaggedData)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 URL (java.net.URL)1