// Path: src/main/java/io/playpen/core/utils/AuthUtils.java
// public class AuthUtils {
// 
//     private static StandardPBEByteEncryptor getEncryptor(String key)
//     {
//         StandardPBEByteEncryptor encryptor = new StandardPBEByteEncryptor();
//         encryptor.setPassword(key);
//         encryptor.setAlgorithm("PBEWithSHA1AndRC4_128");
//         encryptor.setKeyObtentionIterations(4000);
//         return encryptor;
//     }
// 
//     public static byte[] encrypt(byte[] bytes, String key)
//     {
//         StandardPBEByteEncryptor encryptor = getEncryptor(key);
//         return encryptor.encrypt(bytes);
//     }
// 
//     public static byte[] decrypt(byte[] bytes, String key)
//     {
//         StandardPBEByteEncryptor encryptor = getEncryptor(key);
//         return encryptor.decrypt(bytes);
//     }
// 
//     public static String createHash(String key, byte[] message) {
//         MessageDigest digest;
// 
//         try {
//             digest = MessageDigest.getInstance("SHA-1");
//         } catch (NoSuchAlgorithmException e) {
//             throw new AssertionError(e);
//         }
// 
//         digest.update(message);
//         digest.update(key.getBytes(StandardCharsets.UTF_8));
// 
//         return Hex.encodeHexString(digest.digest());
//     }
// 
//     public static String createPackageChecksum(String fp) throws IOException {
//         Path path = Paths.get(fp);
//         try (CheckedInputStream is = new CheckedInputStream(Files.newInputStream(path), new Adler32())) {
//             byte[] buf = new byte[1024*1024];
//             int total = 0;
//             int c = 0;
//             while (total < 100*1024*1024 && (c = is.read(buf)) >= 0) {
//                 total += c;
//             }
// 
//             ByteBuffer bb = ByteBuffer.allocate(Long.BYTES);
//             bb.putLong(path.toFile().length());
//             buf = bb.array();
//             is.getChecksum().update(buf, 0, buf.length);
//             return Long.toHexString(is.getChecksum().getValue());
//         }
//     }
// 
//     public static boolean validateHash(String hash, String key, String message) {
//         return validateHash(hash, key, message.getBytes(StandardCharsets.UTF_8));
//     }
// 
//     public static boolean validateHash(String hash, String key, byte[] message) {
//         return hash.equals(createHash(key, message));
//     }
// 
//     public static boolean validateHash(Protocol.AuthenticatedMessage payload, String key) {
//         return validateHash(payload.getHash(), key, payload.getPayload().toByteArray());
//     }
// 
//     private AuthUtils() {}
// }


import io.playpen.core.utils.AuthUtils;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.json.JSONObject;
import java.io.IOException;
import java.util.*;
    public boolean validate() {
        if(id == null || id.isEmpty() || version == null || version.isEmpty())
            return false;

        for(P3Package p3 : dependencies)
        {
            if(!p3.validate())
                return false;
        }

        return true;
    }

    public void calculateChecksum() throws PackageException {
        calculateChecksum(false);
    }

    public synchronized void calculateChecksum(boolean force) throws PackageException {
        if (!force && checksum != null)
            return;

        if (!resolved)
            throw new PackageException("Cannot calculate checksum on unresolved package");

        if (localPath == null || localPath.isEmpty())
            throw new PackageException("Cannot calculate checksum on package with invalid localPath");

        log.debug("Recalculating checksum on " + id + " (" + version + ")");

        try {
// Path: src/main/java/io/playpen/core/utils/AuthUtils.java
// public class AuthUtils {
// 
//     private static StandardPBEByteEncryptor getEncryptor(String key)
//     {
//         StandardPBEByteEncryptor encryptor = new StandardPBEByteEncryptor();
//         encryptor.setPassword(key);
//         encryptor.setAlgorithm("PBEWithSHA1AndRC4_128");
//         encryptor.setKeyObtentionIterations(4000);
//         return encryptor;
//     }
// 
//     public static byte[] encrypt(byte[] bytes, String key)
//     {
//         StandardPBEByteEncryptor encryptor = getEncryptor(key);
//         return encryptor.encrypt(bytes);
//     }
// 
//     public static byte[] decrypt(byte[] bytes, String key)
//     {
//         StandardPBEByteEncryptor encryptor = getEncryptor(key);
//         return encryptor.decrypt(bytes);
//     }
// 
//     public static String createHash(String key, byte[] message) {
//         MessageDigest digest;
// 
//         try {
//             digest = MessageDigest.getInstance("SHA-1");
//         } catch (NoSuchAlgorithmException e) {
//             throw new AssertionError(e);
//         }
// 
//         digest.update(message);
//         digest.update(key.getBytes(StandardCharsets.UTF_8));
// 
//         return Hex.encodeHexString(digest.digest());
//     }
// 
//     public static String createPackageChecksum(String fp) throws IOException {
//         Path path = Paths.get(fp);
//         try (CheckedInputStream is = new CheckedInputStream(Files.newInputStream(path), new Adler32())) {
//             byte[] buf = new byte[1024*1024];
//             int total = 0;
//             int c = 0;
//             while (total < 100*1024*1024 && (c = is.read(buf)) >= 0) {
//                 total += c;
//             }
// 
//             ByteBuffer bb = ByteBuffer.allocate(Long.BYTES);
//             bb.putLong(path.toFile().length());
//             buf = bb.array();
//             is.getChecksum().update(buf, 0, buf.length);
//             return Long.toHexString(is.getChecksum().getValue());
//         }
//     }
// 
//     public static boolean validateHash(String hash, String key, String message) {
//         return validateHash(hash, key, message.getBytes(StandardCharsets.UTF_8));
//     }
// 
//     public static boolean validateHash(String hash, String key, byte[] message) {
//         return hash.equals(createHash(key, message));
//     }
// 
//     public static boolean validateHash(Protocol.AuthenticatedMessage payload, String key) {
//         return validateHash(payload.getHash(), key, payload.getPayload().toByteArray());
//     }
// 
//     private AuthUtils() {}
// }


// Path: src/main/java/io/playpen/core/p3/P3Package.java
import io.playpen.core.utils.AuthUtils;
import lombok.Data;
import lombok.extern.log4j.Log4j2;
import org.json.JSONObject;
import java.io.IOException;
import java.util.*;

    public boolean validate() {
        if(id == null || id.isEmpty() || version == null || version.isEmpty())
            return false;

        for(P3Package p3 : dependencies)
        {
            if(!p3.validate())
                return false;
        }

        return true;
    }

    public void calculateChecksum() throws PackageException {
        calculateChecksum(false);
    }

    public synchronized void calculateChecksum(boolean force) throws PackageException {
        if (!force && checksum != null)
            return;

        if (!resolved)
            throw new PackageException("Cannot calculate checksum on unresolved package");

        if (localPath == null || localPath.isEmpty())
            throw new PackageException("Cannot calculate checksum on package with invalid localPath");

        log.debug("Recalculating checksum on " + id + " (" + version + ")");

        try {
            checksum = AuthUtils.createPackageChecksum(localPath);