Rev

Rev 2230 | Details | Compare with Previous | Last modification | View Log | SVN | Bug Tracker

Rev Author Line No. Line
1665 garciay 1
/**
2
 * @author      ETSI / STF481 / Yann Garcia
3
 * @version     $URL: file:///D:/RepositoriesNew/ITS/trunk/javasrc/codec/org/etsi/ttcn/codec/its/security/EncryptionParameters.java $
4
 *              $Id: EncryptionParameters.java 2655 2017-01-26 10:46:08Z filatov $
5
 */
1494 garciay 6
package org.etsi.ttcn.codec.its.security;
7
 
8
import org.etsi.ttcn.codec.CodecBuffer;
9
import org.etsi.ttcn.codec.MainCodec;
10
import org.etsi.ttcn.codec.generic.Record;
11
import org.etsi.ttcn.tci.RecordValue;
12
import org.etsi.ttcn.tci.Type;
13
 
14
public class EncryptionParameters extends Record {
15
 
16
    final byte c_aes_128_ccm = 0x00; /** Symmetric key cryptography algorithm AES-CCM as specified in NIST SP 800-38C */
17
 
18
    public EncryptionParameters(MainCodec mainCodec) {
19
        super(mainCodec);
20
        setLengths();
21
    }
22
 
23
    private void setLengths() {
1519 garciay 24
        mainCodec.setHint("SymmetricAlgorithmLen", "8");
1494 garciay 25
    }
26
 
27
    @Override
28
    protected void preDecodeField(String fieldName, CodecBuffer buf, Type decodingHypothesis, RecordValue rv) {
2655 filatov 29
//        TERFactory.getInstance().logDebug(">>> EncryptionParameters.preDecodeField: " + fieldName + ", " + decodingHypothesis.getName() + ", " + rv.getType().getName());
1494 garciay 30
        if (fieldName.equals("symm_algorithm")) {
31
            byte type_ = buf.getBytes(0, 1)[0];
1534 garciay 32
            mainCodec.setHint("SymmetricAlgorithm", String.valueOf(type_));
1494 garciay 33
            switch (type_) {
34
                case (byte)c_aes_128_ccm:
1504 garciay 35
                    mainCodec.setHint("EncryptionParametersContainer", "nonce"); // Set variant 
1494 garciay 36
                    break;
37
                default:
1504 garciay 38
                    mainCodec.setHint("EncryptionParametersContainer", "params"); // Set variant 
1494 garciay 39
            } // End of 'switch' statement
40
        } else {
41
            if (mainCodec.getHint("EncryptionParametersContainer").equals("nonce")) {
1510 garciay 42
                mainCodec.setHint("octetstringLen", "12");
43
                mainCodec.setHint("EncryptionParametersContainer.nonceLen", "12"); // TCT3 Decoding HeaderFieldContainer.enc_params, the type nonce became EncryptionParametersContainer.nonce
1494 garciay 44
            } else {
1510 garciay 45
                int len = buf.readBits(Byte.SIZE)[0]; // field_sizeLen is 1 bytes
1494 garciay 46
                mainCodec.setHint("EncryptionParametersContainer.paramsLen", Integer.toString(len));
47
            }
48
        }
49
    }
50
 
51
} // End of class EncryptionParameters