// Path: src/main/java/org/simplify4u/plugins/pgp/KeyFingerprint.java
// @Value
// @RequiredArgsConstructor
// public class KeyFingerprint {
// 
//     byte[] fingerprint;
// 
//     /**
//      * Construct a key fingerprint from string representation.
//      * @param strFingerprint a key fingerprint as string
//      */
//     public KeyFingerprint(String strFingerprint) {
//         fingerprint = HexUtils.stringToFingerprint(strFingerprint);
//     }
// 
//     @JsonValue
//     public String toString() {
//         return HexUtils.fingerprintToString(fingerprint);
//     }
// }
// 
// Path: src/main/java/org/simplify4u/plugins/pgp/KeyInfo.java
// @Builder
// @Value
// public class KeyInfo {
// 
//     @NonNull
//     KeyFingerprint fingerprint;
// 
//     KeyFingerprint master;
// 
//     Collection<String> uids;
// 
//     int version;
//     int algorithm;
// 
//     int bits;
// 
//     Date date;
// }


import java.io.IOException;
import java.util.Collections;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.bouncycastle.openpgp.PGPException;
import org.simplify4u.plugins.pgp.KeyFingerprint;
import org.simplify4u.plugins.pgp.KeyInfo;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
 * Copyright 2021 Slawomir Jaranowski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.simplify4u.plugins.keysmap;




/**
 * @author Slawomir Jaranowski.
 */
public class KeyItemsTest {

    @DataProvider(name = "keys")
    public Object[][] keys() {
        return new Object[][]{
                {"*", "0x123456789abcdef0", true},
                {"", "0x123456789abcdef0", false},
                {"any", "0x123456789abcdef0", true},
                {"Any", "0x123456789abcdef0", true},
                {"0x123456789abcdef0", "0x123456789abcdef0", true},
                {"noSig, 0x123456789abcdef0", "0x123456789abcdef0", true},
                {"noKey, 0x123456789abcdef0", "0x123456789abcdef0", true},
                {"badSig, 0x123456789abcdef0", "0x123456789abcdef0", true},
                {"0x123456789abcdef0,0x0fedcba987654321", "0x123456789abcdef0", true},
                {"0x123456789abcdef0, 0x0fedcba987654321", "0x123456789abcdef0", true},
                {"0x123456789abcdef0", "0x231456789abcdef0", false},
                {"0x12 34 56 78 9a bc de f0", "0x123456789abcdef0", true},
                {"0x123456789abcdef0, *", "0x231456789abcdef0", true},
                {"0x123456789abcdef0, 0x0fedcba987654321", "0x321456789abcdef0", false},
                {"0x0000000000000001", "0x0000000000000001", true}
        };
    }

    @Test(dataProvider = "keys")
    public void testIsKeyMatch(String strKeys, String key, boolean match) throws Exception {

        KeyItems keyItems = new KeyItems().addKeys(strKeys, null);
        assertThat(keyItems.isKeyMatch(aKeyInfo(key))).as("isKeyMatch").isEqualTo(match);
    }

    private KeyInfo aKeyInfo(String fingerprint) {
// Path: src/main/java/org/simplify4u/plugins/pgp/KeyFingerprint.java
// @Value
// @RequiredArgsConstructor
// public class KeyFingerprint {
// 
//     byte[] fingerprint;
// 
//     /**
//      * Construct a key fingerprint from string representation.
//      * @param strFingerprint a key fingerprint as string
//      */
//     public KeyFingerprint(String strFingerprint) {
//         fingerprint = HexUtils.stringToFingerprint(strFingerprint);
//     }
// 
//     @JsonValue
//     public String toString() {
//         return HexUtils.fingerprintToString(fingerprint);
//     }
// }
// 
// Path: src/main/java/org/simplify4u/plugins/pgp/KeyInfo.java
// @Builder
// @Value
// public class KeyInfo {
// 
//     @NonNull
//     KeyFingerprint fingerprint;
// 
//     KeyFingerprint master;
// 
//     Collection<String> uids;
// 
//     int version;
//     int algorithm;
// 
//     int bits;
// 
//     Date date;
// }


// Path: src/test/java/org/simplify4u/plugins/keysmap/KeyItemsTest.java
import java.io.IOException;
import java.util.Collections;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.bouncycastle.openpgp.PGPException;
import org.simplify4u.plugins.pgp.KeyFingerprint;
import org.simplify4u.plugins.pgp.KeyInfo;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

/*
 * Copyright 2021 Slawomir Jaranowski
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.simplify4u.plugins.keysmap;




/**
 * @author Slawomir Jaranowski.
 */
public class KeyItemsTest {

    @DataProvider(name = "keys")
    public Object[][] keys() {
        return new Object[][]{
                {"*", "0x123456789abcdef0", true},
                {"", "0x123456789abcdef0", false},
                {"any", "0x123456789abcdef0", true},
                {"Any", "0x123456789abcdef0", true},
                {"0x123456789abcdef0", "0x123456789abcdef0", true},
                {"noSig, 0x123456789abcdef0", "0x123456789abcdef0", true},
                {"noKey, 0x123456789abcdef0", "0x123456789abcdef0", true},
                {"badSig, 0x123456789abcdef0", "0x123456789abcdef0", true},
                {"0x123456789abcdef0,0x0fedcba987654321", "0x123456789abcdef0", true},
                {"0x123456789abcdef0, 0x0fedcba987654321", "0x123456789abcdef0", true},
                {"0x123456789abcdef0", "0x231456789abcdef0", false},
                {"0x12 34 56 78 9a bc de f0", "0x123456789abcdef0", true},
                {"0x123456789abcdef0, *", "0x231456789abcdef0", true},
                {"0x123456789abcdef0, 0x0fedcba987654321", "0x321456789abcdef0", false},
                {"0x0000000000000001", "0x0000000000000001", true}
        };
    }

    @Test(dataProvider = "keys")
    public void testIsKeyMatch(String strKeys, String key, boolean match) throws Exception {

        KeyItems keyItems = new KeyItems().addKeys(strKeys, null);
        assertThat(keyItems.isKeyMatch(aKeyInfo(key))).as("isKeyMatch").isEqualTo(match);
    }

    private KeyInfo aKeyInfo(String fingerprint) {
        return KeyInfo.builder().fingerprint(new KeyFingerprint(fingerprint)).build();