libeufin

Integration and sandbox testing for FinTech APIs and data formats
Log | Files | Refs | Submodules | README | LICENSE

MySerializers.kt (1980B)


      1 /*
      2  * This file is part of LibEuFin.
      3  * Copyright (C) 2024 Taler Systems S.A.
      4 
      5  * LibEuFin is free software; you can redistribute it and/or modify
      6  * it under the terms of the GNU Affero General Public License as
      7  * published by the Free Software Foundation; either version 3, or
      8  * (at your option) any later version.
      9 
     10  * LibEuFin is distributed in the hope that it will be useful, but
     11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
     12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero General
     13  * Public License for more details.
     14 
     15  * You should have received a copy of the GNU Affero General Public
     16  * License along with LibEuFin; see the file COPYING.  If not, see
     17  * <http://www.gnu.org/licenses/>
     18  */
     19 
     20 import org.junit.Test
     21 import tech.libeufin.common.Base32Crockford
     22 import tech.libeufin.common.crypto.CryptoUtil
     23 import tech.libeufin.ebics.ClientPrivateKeysFile
     24 import tech.libeufin.ebics.JSON
     25 import kotlin.test.assertEquals
     26 
     27 class MySerializers {
     28     // Testing deserialization of RSA private keys.
     29     @Test
     30     fun rsaPrivDeserialization() {
     31         val s = Base32Crockford.encode(CryptoUtil.genRSAPrivate(2048).encoded)
     32         val a = Base32Crockford.encode(CryptoUtil.genRSAPrivate(2048).encoded)
     33         val e = Base32Crockford.encode(CryptoUtil.genRSAPrivate(2048).encoded)
     34         val obj = JSON.decodeFromString<ClientPrivateKeysFile>("""
     35             {
     36               "signature_private_key": "$s",
     37               "authentication_private_key": "$a",
     38               "encryption_private_key": "$e",
     39               "submitted_ini": true,
     40               "submitted_hia": true
     41             }
     42         """.trimIndent())
     43         assertEquals(obj.signature_private_key, CryptoUtil.loadRSAPrivate(Base32Crockford.decode(s)))
     44         assertEquals(obj.authentication_private_key, CryptoUtil.loadRSAPrivate(Base32Crockford.decode(a)))
     45         assertEquals(obj.encryption_private_key, CryptoUtil.loadRSAPrivate(Base32Crockford.decode(e)))
     46     }
     47 }