extract subkey loading from KeychainProvider
This commit is contained in:
@@ -7,6 +7,7 @@ import android.support.annotation.NonNull;
|
||||
|
||||
import com.squareup.sqldelight.ColumnAdapter;
|
||||
import org.sufficientlysecure.keychain.model.AutocryptPeer.GossipOrigin;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
|
||||
|
||||
|
||||
@@ -50,4 +51,17 @@ public final class CustomColumnAdapters {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static final ColumnAdapter<SecretKeyType,Long> SECRET_KEY_TYPE_ADAPTER = new ColumnAdapter<SecretKeyType, Long>() {
|
||||
@NonNull
|
||||
@Override
|
||||
public SecretKeyType decode(Long databaseValue) {
|
||||
return databaseValue == null ? SecretKeyType.UNAVAILABLE : SecretKeyType.fromNum(databaseValue.intValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long encode(@NonNull SecretKeyType value) {
|
||||
return (long) value.getNum();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,14 +6,23 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
import com.squareup.sqldelight.RowMapper;
|
||||
import org.sufficientlysecure.keychain.KeysModel;
|
||||
import org.sufficientlysecure.keychain.pgp.CanonicalizedSecretKey.SecretKeyType;
|
||||
|
||||
|
||||
@AutoValue
|
||||
public abstract class Key implements KeysModel {
|
||||
public static final Factory<Key> FACTORY = new Factory<>(AutoValue_Key::new);
|
||||
public abstract class SubKey implements KeysModel {
|
||||
public static final Factory<SubKey> FACTORY =
|
||||
new Factory<>(AutoValue_SubKey::new, CustomColumnAdapters.SECRET_KEY_TYPE_ADAPTER);
|
||||
public static final SelectAllUnifiedKeyInfoMapper<UnifiedKeyInfo> UNIFIED_KEY_INFO_MAPPER =
|
||||
FACTORY.selectAllUnifiedKeyInfoMapper(AutoValue_Key_UnifiedKeyInfo::new);
|
||||
FACTORY.selectAllUnifiedKeyInfoMapper(AutoValue_SubKey_UnifiedKeyInfo::new);
|
||||
public static Mapper<SubKey> SUBKEY_MAPPER = new Mapper<>(FACTORY);
|
||||
public static RowMapper<SecretKeyType> SKT_MAPPER = FACTORY.selectSecretKeyTypeMapper();
|
||||
|
||||
public boolean expires() {
|
||||
return expiry() != null;
|
||||
}
|
||||
|
||||
@AutoValue
|
||||
public static abstract class UnifiedKeyInfo implements SelectAllUnifiedKeyInfoModel {
|
||||
@@ -45,6 +54,5 @@ public abstract class Key implements KeysModel {
|
||||
}
|
||||
return autocryptPackageNames;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user