/*
 * Copyright (C) 2025 - 2026, Stephan Mueller <smueller@chronox.de>
 *
 * License: see LICENSE file in root directory
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
 * WHICH ARE HEREBY DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
 * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
 * DAMAGE.
 */

use leancrypto_sys::lcr_bike::lcr_bike;
use leancrypto_sys::lcr_bike::lcr_bike_type;

fn lc_rust_bike_one(bike_type: lcr_bike_type) {
    let mut bike = lcr_bike::new();

    let result = bike.keypair(bike_type);
    assert_eq!(result, Ok(()));

    let result = bike.encapsulate();
    assert_eq!(result, Ok(()));

    let ct_slice = bike.get_ct().expect("get_ct");
    let ct = ct_slice.to_vec();
    let sk_slice = bike.get_sk().expect("get_sk");
    let sk = sk_slice.to_vec();

    let mut bike2 = lcr_bike::new();
    let result = bike2.sk_load(&sk);
    assert_eq!(result, Ok(()));
    assert_eq!(
        bike.get_sk().expect("get_sk"),
        bike2.get_sk().expect("get_sk")
    );

    let result = bike2.ct_load(&ct);
    assert_eq!(result, Ok(()));
    assert_eq!(
        bike.get_ct().expect("get_ct"),
        bike2.get_ct().expect("get_ct")
    );

    let result = bike2.decapsulate();
    assert_eq!(result, Ok(()));
    assert_eq!(
        bike.get_ss().expect("get_ss"),
        bike2.get_ss().expect("get_ss")
    );
    //println!("ct {:x?}",  bike2.get_ct().to_vec().chunks(10).next());
}

#[test]
fn lc_rust_bike_1() {
    lc_rust_bike_one(lcr_bike_type::lcr_bike_1);
}

#[test]
fn lc_rust_bike_3() {
    lc_rust_bike_one(lcr_bike_type::lcr_bike_3);
}

#[test]
fn lc_rust_bike_5() {
    lc_rust_bike_one(lcr_bike_type::lcr_bike_5);
}
