• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ebourg / jsign / #411

09 Jul 2026 08:51AM UTC coverage: 80.874% (+0.006%) from 80.868%
#411

push

ebourg
Removed the obsolete and redundant SPC_GLUE_RDN_OBJID identifier

5125 of 6337 relevant lines covered (80.87%)

0.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.49
/jsign-core/src/main/java/net/jsign/pe/CertificateTableEntry.java
1
/*
2
 * Copyright 2016 Emmanuel Bourg
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
package net.jsign.pe;
18

19
import java.io.IOException;
20
import java.nio.ByteBuffer;
21
import java.nio.ByteOrder;
22

23
import org.bouncycastle.cms.CMSException;
24
import org.bouncycastle.cms.CMSSignedData;
25

26
/**
27
 * Entry of the certificate table.
28
 * 
29
 * @author Emmanuel Bourg
30
 * @since 1.3
31
 */
32
class CertificateTableEntry {
33

34
    private int size;
35
    private int revision;
36
    private int type;
37
    private byte[] content;
38
    private CMSSignedData signature;
39

40
    CertificateTableEntry(PEFile peFile, long index) throws IOException {
1✔
41
        size = (int) peFile.readDWord(index, 0);
1✔
42
        if (size < 8 || size > peFile.channel.size() - index) {
1✔
43
            throw new IOException("Invalid certificate table size: " + size);
1✔
44
        }
45
        revision = peFile.readWord(index, 4);
1✔
46
        type = peFile.readWord(index, 6);
1✔
47
        content = new byte[size - 8];
1✔
48
        peFile.read(content, index, 8);
1✔
49
    }
1✔
50

51
    public CertificateTableEntry(CMSSignedData signature) throws IOException {
1✔
52
        setSignature(signature);
1✔
53
    }
1✔
54

55
    public int getSize() {
56
        return size;
1✔
57
    }
58

59
    public byte[] getContent() {
60
        return content;
1✔
61
    }
62

63
    public boolean isSupported() {
64
        return type == CertificateType.PKCS_SIGNED_DATA.getValue() && revision == 0x0200;
1✔
65
    }
66

67
    @Deprecated
68
    public CMSSignedData getSignature() throws CMSException {
69
        if (!isSupported()) {
×
70
            throw new UnsupportedOperationException("Unsupported certificate type: " + type + " revision: " + revision);
×
71
        }
72
        
73
        if (signature == null) {
×
74
            try {
75
                signature = new CMSSignedData(content);
×
76
            } catch (StackOverflowError e) {
×
77
                throw new IllegalArgumentException("Failed to construct ContentInfo from byte[]: ", e);
×
78
            }
×
79
        }
80
        
81
        return signature;
×
82
    }
83

84
    public void setSignature(CMSSignedData signature) throws IOException {
85
        this.signature = signature;
1✔
86
        byte[] content = signature.toASN1Structure().getEncoded("DER");
1✔
87
        this.content = pad(content, 8);
1✔
88
        this.size = this.content.length + 8;
1✔
89
        this.type = CertificateType.PKCS_SIGNED_DATA.getValue();
1✔
90
    }
1✔
91

92
    private byte[] pad(byte[] data, int multiple) {
93
        if (data.length % multiple == 0) {
1✔
94
            return data;
1✔
95
        } else {
96
            byte[] copy = new byte[data.length + (multiple - data.length % multiple)];
1✔
97
            System.arraycopy(data, 0, copy, 0, data.length);
1✔
98
            return copy;
1✔
99
        }
100
    }
101

102
    public byte[] toBytes() {
103
        ByteBuffer buffer = ByteBuffer.allocate(size);
1✔
104
        buffer.order(ByteOrder.LITTLE_ENDIAN);
1✔
105
        buffer.putInt(buffer.limit());
1✔
106
        buffer.putShort((short) 0x0200);
1✔
107
        buffer.putShort(CertificateType.PKCS_SIGNED_DATA.getValue());
1✔
108
        buffer.put(content);
1✔
109
        
110
        return buffer.array();
1✔
111
    }
112
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc