Created
January 23, 2018 07:23
-
-
Save tonisives/5064c746aee8d41efc093ce248e74a2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.hm.oem.hmcore | |
import com.highmobility.crypto.AccessCertificate | |
import com.highmobility.hmkit.Telematics | |
import com.highmobility.utils.Bytes | |
class CoreTest { | |
// to create access certificate, AccessCertificate constructor should be used | |
/** | |
public AccessCertificate(byte[] gainerSerial, | |
byte[] gainingPublicKey, | |
byte[] providingSerial, | |
byte[] startDate, | |
byte[] endDate, | |
byte[] permissions) throws IllegalArgumentException { | |
*/ | |
def testAccessCert() { | |
val cert = new AccessCertificate(Array[Byte](0, 1)) // this fails, need correct bytes | |
} | |
val telematics = new Telematics() | |
// to encrypt a command, core's encryptCommand should be called | |
def testEncryptCommand() { | |
val privateKeyHex = "AABBCCDDFF00112233" | |
// hex methods are available in Bytes class | |
val privateKeyBytes:Array[Byte] = Bytes.bytesFromHex(privateKeyHex) | |
val privateKeyAgainInHex:String = Bytes.hexFromBytes(privateKeyBytes) | |
val cert = new AccessCertificate(Array[Byte](0, 1)) // need a real cert here | |
val nonce = Array[Byte](0, 1) | |
val serial = Array[Byte](0, 1) | |
val command = Array[Byte](0, 1) | |
val encryptedCommand:Array[Byte] = telematics.encryptCommand(privateKeyBytes, cert, nonce, serial, command) // TODO: this can throw | |
} | |
// to decrypt a command, core's decryptCommand should be called | |
def testDecryptCommand() { | |
val privateKey = Array[Byte](0, 1) | |
val cert = new AccessCertificate(Array[Byte](0, 1)) | |
val command = Array[Byte](0, 1) | |
val decryptedCommand:Array[Byte] = telematics.decryptCommand(privateKey, cert, command) // TODO: this can throw | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment