/// <summary> /// Initializes a new instance of the <see cref="PackageTrusterTests"/> class. /// </summary> public PackageTrusterTests() { Truster = new PackageTruster(); Uri codeBaseUri = new Uri(System.Reflection.Assembly.GetExecutingAssembly().CodeBase); string codeBasePath = Uri.UnescapeDataString(codeBaseUri.AbsolutePath); string dirPath = Path.GetDirectoryName(codeBasePath); DataDirectory = Path.Combine(dirPath, "Data"); TempDirectory = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); Directory.CreateDirectory(TempDirectory); }
/// <summary> /// Processes the desired command with the arguments specified in the command line arguments from Main(). /// </summary> /// <param name="args"> /// The optional command line arguments, used to override the arguments with which the application was started. /// </param> public static void Process(string args = "") { if (args != string.Empty) { Arguments.Populate(args); } string command = string.Empty; try { if (Operands.Count > 1) { command = Operands[1].ToLower(); } if (command == "manifest") { ManifestGenerator generator = new ManifestGenerator(); generator.Updated += Update; PackageManifest manifest = generator.GenerateManifest(Directory, HashFiles, ManifestFile); if (string.IsNullOrEmpty(ManifestFile) && manifest != default(PackageManifest)) { Console.WriteLine(manifest.ToJson()); } } else if (command == "extract-manifest") { ManifestExtractor extractor = new ManifestExtractor(); extractor.Updated += Update; PackageManifest manifest = extractor.ExtractManifest(PackageFile, ManifestFile); if (string.IsNullOrEmpty(ManifestFile) && manifest != default(PackageManifest)) { Console.WriteLine(manifest.ToJson()); } } else if (command == "package") { PackageCreator creator = new PackageCreator(); creator.Updated += Update; string privateKey = string.Empty; if (!string.IsNullOrEmpty(PrivateKeyFile)) { privateKey = File.ReadAllText(PrivateKeyFile); } creator.CreatePackage(Directory, ManifestFile, PackageFile, SignPackage, privateKey, Passphrase, KeybaseUsername); } else if (command == "extract-package") { PackageExtractor extractor = new PackageExtractor(); extractor.Updated += Update; string publicKey = string.Empty; if (!string.IsNullOrEmpty(PublicKeyFile)) { publicKey = File.ReadAllText(PublicKeyFile); } extractor.ExtractPackage(PackageFile, Directory, publicKey, Overwrite, SkipVerification); } else if (command == "trust") { PackageTruster truster = new PackageTruster(); truster.Updated += Update; truster.TrustPackage(PackageFile, File.ReadAllText(PrivateKeyFile), Passphrase); } else if (command == "verify") { PackageVerifier verifier = new PackageVerifier(); verifier.Updated += Update; string publicKey = string.Empty; if (!string.IsNullOrEmpty(PublicKeyFile)) { publicKey = File.ReadAllText(PublicKeyFile); } verifier.VerifyPackage(PackageFile, publicKey); } else { HelpPrinter.PrintHelp(Operands.Count > 2 ? Operands[2] : default(string)); } } catch (Exception ex) { Console.WriteLine($"Error: {ex.Message}"); } }