// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/storage/KeyStorage.java
// public interface KeyStorage {
//     /**
//      * Load key from storage
//      * @return Key if available or null
//      */
//     SecretKey loadKey(Context context);
// 
//     /**
//      * Save key to storage
//      * @return True if successful
//      */
//     boolean saveKey(Context context, SecretKey secretKey);
// 
//     /**
//      * Remove key from storage
//      */
//     void clearKey(Context context);
// 
//     /**
//      * Determine if key is available
//      */
//     boolean hasKey(Context context);
// 
//     /**
//      * Return the type of key storage used.
//      */
//     KeyStorageType getKeyStorageType();
// }
// 
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/storage/KeyStorageType.java
// public enum KeyStorageType {
//     ANDROID_KEYSTORE,
//     ANDROID_KEYSTORE_AUTHENTICATED,
//     OBFUSCATED,
//     NOT_PERSISTENT
// }


import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import com.bottlerocketstudios.vault.keys.storage.KeyStorage;
import com.bottlerocketstudios.vault.keys.storage.KeyStorageType;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import javax.crypto.SecretKey;
/*
 * Copyright (c) 2016. Bottle Rocket LLC
 * 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 com.bottlerocketstudios.vault;





/**
 * SecureVault backed by a SharedPreference file.
 */
public class StandardSharedPreferenceVault implements SharedPreferenceVault {
    private static final String TAG = StandardSharedPreferenceVault.class.getSimpleName();

    private static final String STRING_SET_SEPARATOR = "1eRHtJaybutdAsFp2DkfrT1FqMJlLfT7DdgCpQtTaoQWheoeFBZRqt5pgFDH7Cf";

    private static final Pattern FLOAT_REGEX = Pattern.compile("^-?\\d+\\.\\d+$");
    private static final Pattern INTEGER_REGEX = Pattern.compile("^-?\\d+$");
    private static final Pattern BOOLEAN_REGEX = Pattern.compile("^(true|false)$");

    private final Context mContext;
    private final boolean mEnableExceptions;
    private final String mTransform;
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/storage/KeyStorage.java
// public interface KeyStorage {
//     /**
//      * Load key from storage
//      * @return Key if available or null
//      */
//     SecretKey loadKey(Context context);
// 
//     /**
//      * Save key to storage
//      * @return True if successful
//      */
//     boolean saveKey(Context context, SecretKey secretKey);
// 
//     /**
//      * Remove key from storage
//      */
//     void clearKey(Context context);
// 
//     /**
//      * Determine if key is available
//      */
//     boolean hasKey(Context context);
// 
//     /**
//      * Return the type of key storage used.
//      */
//     KeyStorageType getKeyStorageType();
// }
// 
// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/keys/storage/KeyStorageType.java
// public enum KeyStorageType {
//     ANDROID_KEYSTORE,
//     ANDROID_KEYSTORE_AUTHENTICATED,
//     OBFUSCATED,
//     NOT_PERSISTENT
// }


// Path: AndroidVault/vault/src/main/java/com/bottlerocketstudios/vault/StandardSharedPreferenceVault.java
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import android.util.Log;
import com.bottlerocketstudios.vault.keys.storage.KeyStorage;
import com.bottlerocketstudios.vault.keys.storage.KeyStorageType;
import java.io.UnsupportedEncodingException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import javax.crypto.SecretKey;

/*
 * Copyright (c) 2016. Bottle Rocket LLC
 * 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 com.bottlerocketstudios.vault;





/**
 * SecureVault backed by a SharedPreference file.
 */
public class StandardSharedPreferenceVault implements SharedPreferenceVault {
    private static final String TAG = StandardSharedPreferenceVault.class.getSimpleName();

    private static final String STRING_SET_SEPARATOR = "1eRHtJaybutdAsFp2DkfrT1FqMJlLfT7DdgCpQtTaoQWheoeFBZRqt5pgFDH7Cf";

    private static final Pattern FLOAT_REGEX = Pattern.compile("^-?\\d+\\.\\d+$");
    private static final Pattern INTEGER_REGEX = Pattern.compile("^-?\\d+$");
    private static final Pattern BOOLEAN_REGEX = Pattern.compile("^(true|false)$");

    private final Context mContext;
    private final boolean mEnableExceptions;
    private final String mTransform;
    private final KeyStorage mKeyStorage;