Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.repository/src')
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java31
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java2
-rw-r--r--bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties1
3 files changed, 26 insertions, 8 deletions
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java
index 9f160334a..5e4e2303b 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/ChecksumProducer.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2018 IBM Corporation and others.
+ * Copyright (c) 2009, 2019 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -17,6 +17,9 @@ package org.eclipse.equinox.internal.p2.repository.helpers;
import java.io.*;
import java.security.*;
+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
+import org.eclipse.equinox.internal.p2.repository.Activator;
+import org.eclipse.osgi.util.NLS;
/**
* Calculates a checksum using {@link java.security.MessageDigest}
@@ -34,8 +37,8 @@ public class ChecksumProducer {
// bug #509401 - still here to not break x-friends like in bug #507193
public static String computeMD5(File file) throws IOException {
try {
- return produce(file, "MD5"); //$NON-NLS-1$
- } catch (NoSuchAlgorithmException e) {
+ return produce(file, "MD5", null); //$NON-NLS-1$
+ } catch (NoSuchAlgorithmException | NoSuchProviderException e) {
return null;
}
}
@@ -43,20 +46,34 @@ public class ChecksumProducer {
/**
* @param file should not be <code>null</code>
* @param algorithm {@link java.security.MessageDigest#getInstance(String)}
+ * @param providerName {@link Provider#getName()}
* @return checksum of the file
* @throws IOException
* @throws NoSuchAlgorithmException
+ * @throws NoSuchProviderException
+ * @see {@link java.security.MessageDigest#getInstance(String, Provider)}
*/
- public static String produce(File file, String algorithm) throws IOException, NoSuchAlgorithmException {
- MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
+ public static String produce(File file, String algorithm, String providerName) throws IOException, NoSuchAlgorithmException, NoSuchProviderException {
+ MessageDigest messageDigest = getMessageDigest(algorithm, providerName);
try (InputStream fis = new DigestInputStream(new BufferedInputStream(new FileInputStream(file)), messageDigest)) {
byte[] buffer = new byte[BUFFER_SIZE];
while (fis.read(buffer) != -1) {
// consume stream to update digest
}
+ byte[] digest = messageDigest.digest();
+ return ChecksumHelper.toHexString(digest);
}
- byte[] digest = messageDigest.digest();
- return ChecksumHelper.toHexString(digest);
+ }
+
+ public static MessageDigest getMessageDigest(String algorithm, String providerName) throws NoSuchAlgorithmException, NoSuchProviderException {
+ if (providerName == null)
+ return MessageDigest.getInstance(algorithm);
+
+ Provider provider = ServiceHelper.getService(Activator.getContext(), Provider.class, "(providerName=" + providerName + ")"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (provider == null)
+ throw new NoSuchProviderException(NLS.bind(Messages.noSuchProvider, providerName));
+
+ return MessageDigest.getInstance(algorithm, provider);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java
index 0dcc7e358..b07ee2ce9 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/Messages.java
@@ -38,5 +38,5 @@ class Messages extends NLS {
public static String DestinationNotModifiable;
public static String locationMustBeAbsolute;
public static String schemeNotSupported;
-
+ public static String noSuchProvider;
}
diff --git a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties
index 03fb40287..7261cda8f 100644
--- a/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties
+++ b/bundles/org.eclipse.equinox.p2.repository/src/org/eclipse/equinox/internal/p2/repository/helpers/messages.properties
@@ -22,3 +22,4 @@ repoManAuthenticationFailedFor_0=Authentication failed for {0}
DestinationNotModifiable=Destination repository is not modifiable: {0}
locationMustBeAbsolute=Location must be absolute
schemeNotSupported=Scheme not supported
+noSuchProvider=No such provider: {0}

Back to the top