Change some package structure

This commit is contained in:
Vincent Breitmoser 2017-10-09 14:24:42 +02:00
parent a51252910b
commit 0cb000a0be
10 changed files with 22 additions and 75 deletions

View file

@ -31,6 +31,7 @@ import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.Transport;
import javax.smartcardio.CommandAPDU;
import javax.smartcardio.ResponseAPDU;
import org.sufficientlysecure.keychain.securitytoken.usb.tpdu.T1ShortApduProtocol;
import org.sufficientlysecure.keychain.securitytoken.usb.tpdu.T1TpduProtocol;
import org.sufficientlysecure.keychain.util.Log;

View file

@ -21,7 +21,7 @@ import org.bouncycastle.util.Arrays;
import org.bouncycastle.util.encoders.Hex;
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
public class Block {
class Block {
private static final int MAX_PAYLOAD_LEN = 254;
private static final int OFFSET_NAD = 0;
static final int OFFSET_PCB = 1;
@ -29,9 +29,9 @@ public class Block {
private static final int OFFSET_DATA = 3;
private final byte[] blockData;
private final BlockChecksumType checksumType;
private final BlockChecksumAlgorithm checksumType;
Block(BlockChecksumType checksumType, byte[] data) throws UsbTransportException {
Block(BlockChecksumAlgorithm checksumType, byte[] data) throws UsbTransportException {
this.checksumType = checksumType;
this.blockData = data;
@ -64,7 +64,7 @@ public class Block {
*/
// /*
Block(BlockChecksumType checksumType, byte nad, byte pcb, byte[] apdu, int offset, int length)
Block(BlockChecksumAlgorithm checksumType, byte nad, byte pcb, byte[] apdu, int offset, int length)
throws UsbTransportException {
this.checksumType = checksumType;
if (length > MAX_PAYLOAD_LEN) {
@ -100,7 +100,7 @@ public class Block {
return Arrays.copyOfRange(blockData, blockData.length - checksumType.getLength(), blockData.length);
}
public BlockChecksumType getChecksumType() {
public BlockChecksumAlgorithm getChecksumType() {
return checksumType;
}

View file

@ -19,12 +19,12 @@ package org.sufficientlysecure.keychain.securitytoken.usb.tpdu;
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
public enum BlockChecksumType {
enum BlockChecksumAlgorithm {
LRC(1), CRC(2);
private int mLength;
BlockChecksumType(int length) {
BlockChecksumAlgorithm(int length) {
mLength = length;
}

View file

@ -1,56 +0,0 @@
/*
* Copyright (C) 2016 Nikita Mikhailov <nikita.s.mikhailov@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.securitytoken.usb.tpdu;
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
public enum FrameType {
I_BLOCK(0b00000000, 0b10000000, 6, true), // Information
R_BLOCK(0b10000000, 0b11000000, 4, false), // Receipt ack
S_BLOCK(0b11000000, 0b11000000, -1, false); // System
private byte mValue;
private byte mMask;
private int mSequenceBit;
private boolean mChainingSupported;
FrameType(int value, int mask, int sequenceBit, boolean chaining) {
// Accept ints just to avoid cast in creation
this.mValue = (byte) value;
this.mMask = (byte) mask;
this.mSequenceBit = sequenceBit;
this.mChainingSupported = chaining;
}
public static FrameType fromPCB(byte pcb) throws UsbTransportException {
for (final FrameType frameType : values()) {
if ((frameType.mMask & pcb) == frameType.mValue) {
return frameType;
}
}
throw new UsbTransportException("Invalid PCB byte");
}
public int getSequenceBit() {
return mSequenceBit;
}
public boolean isChainingSupported() {
return mChainingSupported;
}
}

View file

@ -28,7 +28,7 @@ class IBlock extends Block {
private static final byte BIT_SEQUENCE = 6;
private static final byte BIT_CHAINING = 5;
IBlock(BlockChecksumType checksumType, byte[] data) throws UsbTransportException {
IBlock(BlockChecksumAlgorithm checksumType, byte[] data) throws UsbTransportException {
super(checksumType, data);
if ((getPcb() & MASK_IBLOCK) != MASK_VALUE_IBLOCK) {
@ -36,7 +36,7 @@ class IBlock extends Block {
}
}
IBlock(BlockChecksumType checksumType, byte nad, byte sequence, boolean chaining, byte[] apdu, int offset,
IBlock(BlockChecksumAlgorithm checksumType, byte nad, byte sequence, boolean chaining, byte[] apdu, int offset,
int length)
throws UsbTransportException {
super(checksumType, nad,

View file

@ -27,7 +27,7 @@ class RBlock extends Block {
private static final byte BIT_SEQUENCE = 4;
RBlock(BlockChecksumType checksumType, byte[] data) throws UsbTransportException {
RBlock(BlockChecksumAlgorithm checksumType, byte[] data) throws UsbTransportException {
super(checksumType, data);
if ((getPcb() & MASK_RBLOCK) != MASK_VALUE_RBLOCK) {
@ -39,7 +39,7 @@ class RBlock extends Block {
}
}
RBlock(BlockChecksumType checksumType, byte nad, byte sequence)
RBlock(BlockChecksumAlgorithm checksumType, byte nad, byte sequence)
throws UsbTransportException {
super(checksumType, nad, (byte) (MASK_VALUE_RBLOCK | ((sequence & 1) << BIT_SEQUENCE)), new byte[0], 0, 0);
}

View file

@ -25,7 +25,7 @@ class SBlock extends Block {
static final byte MASK_SBLOCK = (byte) 0b11000000;
static final byte MASK_VALUE_SBLOCK = (byte) 0b11000000;
SBlock(BlockChecksumType checksumType, byte[] data) throws UsbTransportException {
SBlock(BlockChecksumAlgorithm checksumType, byte[] data) throws UsbTransportException {
super(checksumType, data);
if ((getPcb() & MASK_SBLOCK) != MASK_VALUE_SBLOCK) {

View file

@ -15,15 +15,17 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.securitytoken.usb;
package org.sufficientlysecure.keychain.securitytoken.usb.tpdu;
import android.support.annotation.NonNull;
import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.securitytoken.usb.CcidTransceiver;
import org.sufficientlysecure.keychain.securitytoken.usb.CcidTransceiver.CcidDataBlock;
import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.securitytoken.usb.CcidTransportProtocol;
import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
class T1ShortApduProtocol implements CcidTransportProtocol {
public class T1ShortApduProtocol implements CcidTransportProtocol {
private CcidTransceiver ccidTransceiver;
public void connect(@NonNull CcidTransceiver transceiver) throws UsbTransportException {

View file

@ -5,9 +5,9 @@ import org.sufficientlysecure.keychain.securitytoken.usb.UsbTransportException;
class T1TpduBlockFactory {
private BlockChecksumType checksumType;
private BlockChecksumAlgorithm checksumType;
T1TpduBlockFactory(BlockChecksumType checksumType) {
T1TpduBlockFactory(BlockChecksumAlgorithm checksumType) {
this.checksumType = checksumType;
}

View file

@ -47,7 +47,7 @@ public class T1TpduProtocol implements CcidTransportProtocol {
this.ccidTransceiver.iccPowerOn();
// TODO: set checksum from atr
blockFactory = new T1TpduBlockFactory(BlockChecksumType.LRC);
blockFactory = new T1TpduBlockFactory(BlockChecksumAlgorithm.LRC);
performPpsExchange();
}