oltu-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1243347 - in /incubator/amber/trunk: signature-api/src/main/java/org/apache/amber/signature/ signature-api/src/main/java/org/apache/amber/signature/hmac/ signature-api/src/main/java/org/apache/amber/signature/plaintext/ signature-api/src/m...
Date Sun, 12 Feb 2012 22:30:37 GMT
Author: simonetripodi
Date: Sun Feb 12 22:30:37 2012
New Revision: 1243347

URL: http://svn.apache.org/viewvc?rev=1243347&view=rev
Log:
restrict using keys in different methods using generics

Modified:
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/hmac/HmacSha1Method.java
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/plaintext/PlaintextMethod.java
    incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
    incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/AbstractMethodTestCase.java
    incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/signature/SignatureMethod.java

Modified: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java?rev=1243347&r1=1243346&r2=1243347&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/AbstractMethod.java
Sun Feb 12 22:30:37 2012
@@ -38,7 +38,8 @@ import org.apache.commons.logging.LogFac
  *
  * @version $Id$
  */
-public abstract class AbstractMethod implements SignatureMethod {
+public abstract class AbstractMethod<SK extends SigningKey, VK extends VerifyingKey>
+    implements SignatureMethod<SK, VK> {
 
     /**
      * HTTP protocol name.
@@ -123,7 +124,7 @@ public abstract class AbstractMethod imp
     /**
      * {@inheritDoc}
      */
-    public final String calculate(SigningKey signingKey,
+    public final String calculate(SK signingKey,
             OAuthToken token,
             OAuthRequest request) throws SignatureException {
         if (signingKey == null) {
@@ -148,13 +149,13 @@ public abstract class AbstractMethod imp
      * @return the calculated signature.
      * @throws SignatureException if any error occurs.
      */
-    protected abstract String calculate(SigningKey signingKey, String tokenSecret, String
baseString) throws SignatureException;
+    protected abstract String calculate(SK signingKey, String tokenSecret, String baseString)
throws SignatureException;
 
     /**
      * {@inheritDoc}
      */
     public final boolean verify(String signature,
-            VerifyingKey verifyingKey,
+            VK verifyingKey,
             OAuthToken token,
             OAuthRequest request) throws SignatureException {
         if (signature == null) {
@@ -183,7 +184,7 @@ public abstract class AbstractMethod imp
      * @return true if the signature is verified, false otherwise.
      * @throws SignatureException if any error occurs.
      */
-    protected abstract boolean verify(String signature, VerifyingKey verifyingKey, String
tokenSecret, String baseString) throws SignatureException;
+    protected abstract boolean verify(String signature, VK verifyingKey, String tokenSecret,
String baseString) throws SignatureException;
 
     /**
      *

Modified: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/hmac/HmacSha1Method.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/hmac/HmacSha1Method.java?rev=1243347&r1=1243346&r2=1243347&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/hmac/HmacSha1Method.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/hmac/HmacSha1Method.java
Sun Feb 12 22:30:37 2012
@@ -32,7 +32,7 @@ import org.apache.amber.signature.Verify
  *
  * @version $Id$
  */
-public final class HmacSha1Method extends AbstractMethod {
+public final class HmacSha1Method extends AbstractMethod<SigningKey, VerifyingKey>
{
 
     private static final String HMAC_SHA1 = "HMAC-SHA1";
 

Modified: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/plaintext/PlaintextMethod.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/plaintext/PlaintextMethod.java?rev=1243347&r1=1243346&r2=1243347&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/plaintext/PlaintextMethod.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/plaintext/PlaintextMethod.java
Sun Feb 12 22:30:37 2012
@@ -26,7 +26,7 @@ import org.apache.amber.signature.Verify
  *
  * @version $Id$
  */
-public final class PlaintextMethod extends AbstractMethod {
+public final class PlaintextMethod extends AbstractMethod<SigningKey, VerifyingKey>
{
 
     private static final String PLAINTEXT = "PLAINTEXT";
 

Modified: incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java?rev=1243347&r1=1243346&r2=1243347&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
(original)
+++ incubator/amber/trunk/signature-api/src/main/java/org/apache/amber/signature/rsa/RsaSha1Method.java
Sun Feb 12 22:30:37 2012
@@ -20,15 +20,13 @@ import java.security.Signature;
 
 import org.apache.amber.signature.AbstractMethod;
 import org.apache.amber.signature.SignatureException;
-import org.apache.amber.signature.SigningKey;
-import org.apache.amber.signature.VerifyingKey;
 
 /**
  * RSA-SHA1 Method implementation.
  *
  * @version $Id$
  */
-public final class RsaSha1Method extends AbstractMethod {
+public final class RsaSha1Method extends AbstractMethod<RsaSha1SigningKey, RsaSha1VerifyingKey>
{
 
     /**
      * RSA+SHA1 algorithm name.
@@ -52,12 +50,12 @@ public final class RsaSha1Method extends
      * {@inheritDoc}
      */
     @Override
-    protected String calculate(SigningKey signingKey,
+    protected String calculate(RsaSha1SigningKey signingKey,
             String tokenSecret,
             String baseString) throws SignatureException {
         try {
             Signature signer = Signature.getInstance(RSA_SHA1_ALGORITHM);
-            signer.initSign(((RsaSha1SigningKey) signingKey).getPrivateKey());
+            signer.initSign(signingKey.getPrivateKey());
             signer.update(toUTF8Bytes(baseString));
             byte[] signature = signer.sign();
 
@@ -73,12 +71,12 @@ public final class RsaSha1Method extends
      */
     @Override
     protected boolean verify(String signature,
-            VerifyingKey verifyingKey,
+            RsaSha1VerifyingKey verifyingKey,
             String tokenSecret,
             String baseString) throws SignatureException {
         try {
             Signature verifier = Signature.getInstance(RSA_SHA1_ALGORITHM);
-            verifier.initVerify(((RsaSha1VerifyingKey) verifyingKey).getPublicKey());
+            verifier.initVerify(verifyingKey.getPublicKey());
             verifier.update(toUTF8Bytes(baseString));
 
             return verifier.verify(decodeBase64(signature));

Modified: incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/AbstractMethodTestCase.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/AbstractMethodTestCase.java?rev=1243347&r1=1243346&r2=1243347&view=diff
==============================================================================
--- incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/AbstractMethodTestCase.java
(original)
+++ incubator/amber/trunk/signature-api/src/test/java/org/apache/amber/signature/AbstractMethodTestCase.java
Sun Feb 12 22:30:37 2012
@@ -35,8 +35,8 @@ import org.apache.amber.Version;
  */
 public abstract class AbstractMethodTestCase {
 
-    protected void verifySignature(VerifyingKey verifyingKey,
-            SignatureMethod signatureMethod,
+    protected <SK extends SigningKey, VK extends VerifyingKey> void verifySignature(VK
verifyingKey,
+            SignatureMethod<SK, VK> signatureMethod,
             String expectedSignature) throws Exception {
         OAuthRequest request = new FakeOAuthRequest();
         request.setRequestURL(URI.create("http://photos.example.net/photos"));

Modified: incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/signature/SignatureMethod.java
URL: http://svn.apache.org/viewvc/incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/signature/SignatureMethod.java?rev=1243347&r1=1243346&r2=1243347&view=diff
==============================================================================
--- incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/signature/SignatureMethod.java
(original)
+++ incubator/amber/trunk/spec-api/src/main/java/org/apache/amber/signature/SignatureMethod.java
Sun Feb 12 22:30:37 2012
@@ -24,7 +24,7 @@ import org.apache.amber.OAuthToken;
  *
  * @version $Id$
  */
-public interface SignatureMethod {
+public interface SignatureMethod<SK extends SigningKey, VK extends VerifyingKey> {
 
     /**
      * Returns the signing algorithm method.
@@ -43,7 +43,7 @@ public interface SignatureMethod {
      * @return the calculated signature.
      * @throws SignatureException if any error occurs.
      */
-    String calculate(SigningKey signingKey,
+    String calculate(SK signingKey,
             OAuthToken token,
             OAuthRequest request) throws SignatureException;
 
@@ -59,7 +59,7 @@ public interface SignatureMethod {
      * @throws SignatureException if any error occurs.
      */
     boolean verify(String signature,
-            VerifyingKey verifyingKey,
+            VK verifyingKey,
             OAuthToken token,
             OAuthRequest request) throws SignatureException;
 



Mime
View raw message