Skip to content

Commit

Permalink
Add support for SHA256HEADER, FILE_DIGESTALGO, and Zstd compression
Browse files Browse the repository at this point in the history
Signed-off-by: David Walluck <dwalluck@redhat.com>
  • Loading branch information
dwalluck authored and ctron committed May 31, 2019
1 parent 0c73091 commit 2ae1880
Show file tree
Hide file tree
Showing 18 changed files with 927 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public enum RpmSignatureTag implements RpmBaseTag
RSAHEADER ( 268 ),
SHA1HEADER ( 269 ),
LONGARCHIVESIZE ( 271 ),
SHA256HEADER ( 273 ),

SIZE ( 1000 ),
PGP ( 1002 ),
Expand Down
1 change: 1 addition & 0 deletions rpm/src/main/java/org/eclipse/packager/rpm/RpmTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public enum RpmTag implements RpmBaseTag
PAYLOAD_FLAGS ( 1126 ),
PLATFORM ( 1132 ),
LONGSIZE ( 5009 ),
FILE_DIGESTALGO ( 5011 ),
RECOMMEND_NAME ( 5046 ),
RECOMMEND_VERSION ( 5047 ),
RECOMMEND_FLAGS ( 5048 ),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) 2015, 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.packager.rpm.build;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
import org.eclipse.packager.rpm.deps.Dependency;
import org.eclipse.packager.rpm.deps.RpmDependencyFlags;

public class BZip2PayloadCoding implements PayloadCoding
{
protected BZip2PayloadCoding ()
{

}

@Override
public String getCoding ()
{
return "bzip2";
}

@Override
public Optional<Dependency> getDependency ()
{
return Optional.of ( new Dependency ( "PayloadIsBzip2", "3.0.5-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
}

@Override
public InputStream createInputStream ( final InputStream in ) throws IOException
{
return new BZip2CompressorInputStream ( in );
}

@Override
public OutputStream createOutputStream ( final OutputStream out, final Optional<String> optionalFlags ) throws IOException
{
final String flags;

final int blockSize;

if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length() > 0 )
{
blockSize = Integer.parseInt ( flags.substring ( 0, 1 ) );
}
else
{
blockSize = BZip2CompressorOutputStream.MAX_BLOCKSIZE;
}

return new BZip2CompressorOutputStream ( out, blockSize );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package org.eclipse.packager.rpm.build;

import java.io.IOException;
import java.nio.file.OpenOption;
import java.nio.file.StandardOpenOption;
import java.util.Arrays;
Expand All @@ -32,6 +33,12 @@ public class BuilderOptions

private RpmFileNameProvider fileNameProvider = RpmFileNameProvider.LEGACY_FILENAME_PROVIDER;

private PayloadCoding payloadCoding;

private String payloadFlags;

private DigestAlgorithm fileDigestAlgorithm = DigestAlgorithm.MD5;

public BuilderOptions ()
{
}
Expand All @@ -40,6 +47,9 @@ public BuilderOptions ( final BuilderOptions other )
{
setLongMode ( other.longMode );
setOpenOptions ( other.openOptions );
setPayloadCoding ( other.payloadCoding );
setPayloadFlags ( other.payloadFlags );
setFileDigestAlgorithm ( other.fileDigestAlgorithm );
}

public LongMode getLongMode ()
Expand Down Expand Up @@ -79,4 +89,39 @@ public void setFileNameProvider ( final RpmFileNameProvider fileNameProvider )
{
this.fileNameProvider = fileNameProvider != null ? fileNameProvider : RpmFileNameProvider.LEGACY_FILENAME_PROVIDER;
}

public PayloadCoding getPayloadCoding () throws IOException
{
if ( this.payloadCoding == null )
{
this.payloadCoding = PayloadCodingRegistry.get ( PayloadCodingRegistry.GZIP );
}

return this.payloadCoding;
}

public void setPayloadCoding ( final PayloadCoding payloadCoding )
{
this.payloadCoding = payloadCoding;
}

public String getPayloadFlags ()
{
return this.payloadFlags;
}

public void setPayloadFlags ( final String payloadFlags )
{
this.payloadFlags = payloadFlags;
}

public DigestAlgorithm getFileDigestAlgorithm ()
{
return this.fileDigestAlgorithm;
}

public void setFileDigestAlgorithm ( final DigestAlgorithm fileDigestAlgorithm )
{
this.fileDigestAlgorithm = fileDigestAlgorithm == null ? DigestAlgorithm.MD5 : fileDigestAlgorithm;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* Copyright (c) 2015, 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.packager.rpm.build;

import java.io.IOException;

import org.bouncycastle.bcpg.HashAlgorithmTags;

public enum DigestAlgorithm
{
MD5 ( "MD5", HashAlgorithmTags.MD5 ),
SHA1 ( "SHA", HashAlgorithmTags.SHA1 ),
RIPEMD160 ( "RIPE-MD160", HashAlgorithmTags.RIPEMD160 ),
DOUBLE_SHA ( "Double-SHA", HashAlgorithmTags.DOUBLE_SHA ),
MD2 ( "MD2", HashAlgorithmTags.MD2 ),
TIGER_192 ( "Tiger-192", HashAlgorithmTags.TIGER_192 ),
HAVAL_5_160 ( "Haval-5-160", HashAlgorithmTags.HAVAL_5_160 ),
SHA256 ( "SHA-256", HashAlgorithmTags.SHA256 ),
SHA384 ( "SHA-384", HashAlgorithmTags.SHA384 ),
SHA512 ( "SHA-512", HashAlgorithmTags.SHA512 ),
SHA224 ( "SHA-224", HashAlgorithmTags.SHA224 );

private String algorithm;

private int tag;

private DigestAlgorithm ( final String algorithm, final int tag )
{
this.algorithm = algorithm;
this.tag = tag;
}

public String getAlgorithm ()
{
return algorithm;
}

public int getTag ()
{
return tag;
}

public static DigestAlgorithm fromTag ( final int tag ) throws IOException
{
for ( DigestAlgorithm digestAlgorithm : DigestAlgorithm.values () )
{
if ( tag == digestAlgorithm.getTag () )
{
return digestAlgorithm;
}
}

throw new IOException ( String.format ( "Unknown tag: %d", tag ) );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* Copyright (c) 2015, 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.packager.rpm.build;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;
import java.util.zip.Deflater;

import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
import org.apache.commons.compress.compressors.gzip.GzipParameters;
import org.eclipse.packager.rpm.deps.Dependency;

public class GzipPayloadCoding implements PayloadCoding
{
protected GzipPayloadCoding ()
{

}

@Override
public String getCoding ()
{
return "gzip";
}

@Override
public Optional<Dependency> getDependency ()
{
return Optional.empty ();
}

@Override
public InputStream createInputStream ( final InputStream in ) throws IOException
{
return new GzipCompressorInputStream ( in );
}

@Override
public OutputStream createOutputStream ( final OutputStream out, final Optional<String> optionalFlags ) throws IOException
{
final String flags;
final int compressionLevel;

if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length() > 0 )
{
compressionLevel = Integer.parseInt ( flags.substring ( 0, 1 ) );
}
else
{
compressionLevel = Deflater.BEST_COMPRESSION;
}

final GzipParameters parameters = new GzipParameters ();

parameters.setCompressionLevel ( compressionLevel );

return new GzipCompressorOutputStream ( out, parameters );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Copyright (c) 2015, 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.packager.rpm.build;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Optional;

import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream;
import org.apache.commons.compress.compressors.lzma.LZMACompressorOutputStream;
import org.eclipse.packager.rpm.deps.Dependency;
import org.eclipse.packager.rpm.deps.RpmDependencyFlags;

public class LZMAPayloadCoding implements PayloadCoding
{
protected LZMAPayloadCoding ()
{

}

@Override
public String getCoding ()
{
return "lzma";
}

@Override
public Optional<Dependency> getDependency ()
{
return Optional.of ( new Dependency ( "PayloadIsLzma", "4.4.6-1", RpmDependencyFlags.LESS, RpmDependencyFlags.EQUAL, RpmDependencyFlags.RPMLIB ) );
}

@Override
public InputStream createInputStream ( final InputStream in ) throws IOException
{
return new LZMACompressorInputStream ( in );
}

@Override
public OutputStream createOutputStream ( final OutputStream out, final Optional<String> optionalFlags ) throws IOException
{
return new LZMACompressorOutputStream ( out );
}
}
Loading

0 comments on commit 2ae1880

Please sign in to comment.