/** * Loads the repository transfer object from the local directory. */ public static RepoTO loadRepoTO(File localDir, ConfigTO configTO) throws ConfigException { File appDir = new File(localDir, Config.DIR_APPLICATION); File repoFile = new File(appDir, Config.FILE_REPO); if (!repoFile.exists()) { throw new ConfigException("Cannot find repository file at "+repoFile+". Try connecting to a repository using 'connect', or 'init' to create a new one."); } try { if (CipherUtil.isEncrypted(repoFile)) { return loadEncryptedRepoTO(repoFile, configTO); } else { return loadPlaintextRepoTO(repoFile, configTO); } } catch (Exception e) { throw new ConfigException("Cannot load repo file: "+e.getMessage(), e); } }
@Test public void testIsEncryptedFileTrue() throws Exception { File tempDirectory = TestFileUtil.createTempDirectoryInSystemTemp(); File testFile = new File(tempDirectory+"/somefile"); RandomAccessFile testFileRaf = new RandomAccessFile(testFile, "rw"); testFileRaf.write(MultiCipherOutputStream.STREAM_MAGIC); testFileRaf.write(MultiCipherOutputStream.STREAM_VERSION); testFileRaf.close(); assertTrue(CipherUtil.isEncrypted(testFile)); TestFileUtil.deleteDirectory(tempDirectory); }
if (CipherUtil.isEncrypted(tmpRepoFile)) { logger.log(Level.INFO, "- Repo is ENCRYPTED. Decryption necessary.");
@Test public void testIsEncryptedFileFalse() throws Exception { File tempDirectory = TestFileUtil.createTempDirectoryInSystemTemp(); File testFile = new File(tempDirectory+"/somefile"); TestFileUtil.writeToFile(new byte[] { 1, 2, 3 }, testFile); assertFalse(CipherUtil.isEncrypted(testFile)); TestFileUtil.deleteDirectory(tempDirectory); }