public void CreatePackageTest() { var krgen = PgpSigner.GenerateKeyRingGenerator("dotnet", "dotnet"); var secretKeyRing = krgen.GenerateSecretKeyRing(); var privateKey = secretKeyRing.GetSecretKey().ExtractPrivateKey("dotnet".ToCharArray()); var publicKey = secretKeyRing.GetPublicKey(); using (Stream stream = File.OpenRead(@"Rpm\libplist-2.0.1.151-1.1.x86_64.rpm")) using (var targetStream = File.Open(@"RpmPackageCreatorTests_CreateTest.rpm", FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { var originalPackage = RpmPackageReader.Read(stream); List <ArchiveEntry> archive = null; using (var decompressedPayloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage)) using (CpioFile cpio = new CpioFile(decompressedPayloadStream, leaveOpen: false)) { ArchiveBuilder builder = new ArchiveBuilder(); archive = builder.FromCpio(cpio); } using (var decompressedPayloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage)) using (var payloadStream = new MemoryStream()) { decompressedPayloadStream.CopyTo(payloadStream); payloadStream.Position = 0; RpmPackageCreator creator = new RpmPackageCreator(new PlistFileAnalyzer()); creator.CreatePackage( archive, payloadStream, "libplist", "2.0.1.151", "x86_64", "1.1", false, null, false, null, null, null, (metadata) => PlistMetadata.ApplyDefaultMetadata(metadata), privateKey, targetStream); } } using (var targetStream = File.Open(@"RpmPackageCreatorTests_CreateTest.rpm", FileMode.Open, FileAccess.Read, FileShare.None)) { var package = RpmPackageReader.Read(targetStream); var metadata = new RpmMetadata(package); var signature = new RpmSignature(package); Assert.True(signature.Verify(publicKey)); } }
public void VerifyTest() { using (Stream stream = File.OpenRead(@"Rpm/libplist-2.0.1.151-1.1.x86_64.rpm")) using (Stream pgpKey = File.OpenRead(@"Rpm/_key.pub")) { var package = RpmPackageReader.Read(stream); var signature = new RpmSignature(package); signature.Verify(pgpKey); } }
public void CreatePackageTest() { var krgen = PgpSigner.GenerateKeyRingGenerator("dotnet", "dotnet"); var secretKeyRing = krgen.GenerateSecretKeyRing(); var privateKey = secretKeyRing.GetSecretKey().ExtractPrivateKey("dotnet".ToCharArray()); var publicKey = secretKeyRing.GetPublicKey(); const string preInstScript = "echo preinst\n"; const string postInstScript = "echo postinst\n"; const string preRemoveScript = "echo preremove\n"; const string postRemoveScript = "echo postremove\n"; const string nameString = "libplist"; const string versionString = "2.0.1.151"; const string releaseString = "1.1"; const string archString = "x86_64"; using (Stream stream = File.OpenRead($"Rpm/{nameString}-{versionString}-{releaseString}.{archString}.rpm")) using (var targetStream = File.Open(@"RpmPackageCreatorTests_CreateTest.rpm", FileMode.Create, FileAccess.ReadWrite, FileShare.None)) { var originalPackage = RpmPackageReader.Read(stream); List <ArchiveEntry> archive = null; using (var decompressedPayloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage)) using (CpioFile cpio = new CpioFile(decompressedPayloadStream, leaveOpen: false)) { ArchiveBuilder builder = new ArchiveBuilder(); archive = builder.FromCpio(cpio); } using (var decompressedPayloadStream = RpmPayloadReader.GetDecompressedPayloadStream(originalPackage)) using (var payloadStream = new MemoryStream()) { decompressedPayloadStream.CopyTo(payloadStream); payloadStream.Position = 0; RpmPackageCreator creator = new RpmPackageCreator(new PlistFileAnalyzer()); creator.CreatePackage( archive, payloadStream, nameString, versionString, archString, releaseString, false, null, false, null, null, preInstScript, postInstScript, preRemoveScript, postRemoveScript, null, (metadata) => PlistMetadata.ApplyDefaultMetadata(metadata), privateKey, targetStream); } } using (var targetStream = File.Open(@"RpmPackageCreatorTests_CreateTest.rpm", FileMode.Open, FileAccess.Read, FileShare.None)) { var package = RpmPackageReader.Read(targetStream); var metadata = new RpmMetadata(package); Assert.Equal(metadata.Version, versionString); Assert.Equal(metadata.Name, nameString); Assert.Equal(metadata.Arch, archString); Assert.Equal(metadata.Release, releaseString); Assert.StartsWith(preInstScript, metadata.PreIn); Assert.StartsWith(postInstScript, metadata.PostIn); Assert.StartsWith(preRemoveScript, metadata.PreUn); Assert.StartsWith(postRemoveScript, metadata.PostUn); var signature = new RpmSignature(package); Assert.True(signature.Verify(publicKey)); } }