1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.rendering.signature.internal

File MacroBlockSignatureVerifier.java

 
testIncompatibleBlockVerification: Unsupported block [org.xwiki.rendering.block.WordBlock].
 

Coverage histogram

../../../../../img/srcFileCovDistChart8.png
54% of files have more coverage

Code metrics

2
4
2
1
75
39
3
0.75
2
2
1.5

Classes

Class Line # Actions
MacroBlockSignatureVerifier 48 4 0% 3 2
0.7575%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.rendering.signature.internal;
21   
22    import java.io.IOException;
23    import java.security.GeneralSecurityException;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.crypto.pkix.CertificateProvider;
31    import org.xwiki.crypto.signer.CMSSignedDataVerifier;
32    import org.xwiki.crypto.signer.param.CMSSignedDataVerified;
33    import org.xwiki.rendering.block.Block;
34    import org.xwiki.rendering.block.MacroBlock;
35    import org.xwiki.rendering.block.MacroMarkerBlock;
36    import org.xwiki.rendering.signature.BlockSignatureVerifier;
37   
38    /**
39    * Verify signature of {@link org.xwiki.rendering.block.MacroBlock}
40    * and {@link org.xwiki.rendering.block.MacroMarkerBlock}.
41    *
42    * @version $Id: 04201baa08356d31a57107c2255018b253c1512a $
43    * @since 6.1M2
44    */
45    @Component
46    @Named("macro")
47    @Singleton
 
48    public class MacroBlockSignatureVerifier implements BlockSignatureVerifier
49    {
50    @Inject
51    @Named("macro")
52    private BlockDumper dumper;
53   
54    @Inject
55    private CMSSignedDataVerifier verifier;
56   
 
57  3 toggle @Override
58    public CMSSignedDataVerified verify(byte[] signature, Block block, CertificateProvider certificateProvider)
59    throws GeneralSecurityException, IOException
60    {
61  2 if (!isSupported(block)) {
62  0 Test failure here throw new IllegalArgumentException("Unsupported block [" + block.getClass().getName() + "].");
63    }
64   
65  2 return verifier.verify(signature, dumper.dump(block), certificateProvider);
66    }
67   
 
68  3 toggle @Override
69    public boolean isSupported(Block block)
70    {
71  3 return (block instanceof MacroBlock || block instanceof MacroMarkerBlock);
72    }
73   
74    }
75