1 /*
2 * The contents of this file are subject to the terms of the Common Development and
3 * Distribution License (the License). You may not use this file except in compliance with the
4 * License.
5 *
6 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
7 * specific language governing permission and limitations under the License.
8 *
9 * When distributing Covered Software, include this CDDL Header Notice in each file and include
10 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
11 * Header, with the fields enclosed by brackets [] replaced by your own identifying
12 * information: "Portions copyright [year] [name of copyright owner]".
13 *
14 * Copyright 2013-2015 ForgeRock AS.
15 */
16
17 package org.forgerock.json.jose.jws.handlers;
18
19 import org.forgerock.json.jose.jws.JwsAlgorithm;
20 import org.forgerock.json.jose.utils.Utils;
21
22 /**
23 * An implementation of the SigningHandler which does not perform any signing or verifying.
24 *
25 * @since 2.0.0
26 */
27 public class NOPSigningHandler implements SigningHandler {
28
29 /**
30 * Simply returns a byte array of a UTF-8 empty string.
31 *
32 * @param algorithm {@inheritDoc}
33 * @param data {@inheritDoc}
34 * @return {@inheritDoc}
35 */
36 @Override
37 public byte[] sign(JwsAlgorithm algorithm, String data) {
38 return "".getBytes(Utils.CHARSET);
39 }
40
41 /**
42 * Returns an empty byte array.
43 *
44 * @param algorithm {@inheritDoc}
45 * @param data {@inheritDoc}
46 * @return {@inheritDoc}
47 */
48 @Override
49 public byte[] sign(final JwsAlgorithm algorithm, final byte[] data) {
50 return new byte[0];
51 }
52
53 /**
54 * Verifies that the signature length is zero.
55 *
56 * @param algorithm {@inheritDoc}
57 * @param data {@inheritDoc}
58 * @param signature {@inheritDoc}
59 * @return {@inheritDoc}
60 */
61 @Override
62 public boolean verify(JwsAlgorithm algorithm, byte[] data, byte[] signature) {
63 return signature.length == 0;
64 }
65 }