/**
 * Copyright (c) 2020, 2021 Oracle and/or its affiliates.  All rights reserved.
 * This software is dual-licensed to you under the Universal Permissive License (UPL) 1.0 as shown at https://oss.oracle.com/licenses/upl or Apache License 2.0 as shown at http://www.apache.org/licenses/LICENSE-2.0. You may choose either license.
 */ import SessionKeySupplier from "./models/session-key-supplier" ; import KeyPair from "./key-pair" ; import { loadPrivateKeyFromFile } from "./helpers/load-private-key-from-file" ; export default class FileBasedKeySupplier implements SessionKeySupplier { private keyPair ! : KeyPair ; constructor ( private privateKeyPath , private passphrasePath ? ) { this . refreshKeys ( ) ; } public getKeyPair ( ) { return this . keyPair ; } public get publicKey ( ) : string { return this . getKeyPair ( ) . getPublic ( ) ; } public get privateKey ( ) : string { return this . getKeyPair ( ) . getPrivate ( ) ; } public refreshKeys ( ) { if ( ! this . privateKeyPath ) { throw Error ( "privateKeyPath not set" ) ; } try { const { publicKey , privateKey } = loadPrivateKeyFromFile ( this . privateKeyPath , this . passphrasePath ) ; this . keyPair = new KeyPair ( publicKey , privateKey ) ; } catch ( e ) { throw Error ( `Problem occured trying to create KeyPairs from given paths with error: ${ e }` ) ; } } }