| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.net.vcn.persistablebundleutils; |
| 18 |
|
| 19 |
import static com.android.internal.annotations.VisibleForTesting.Visibility; |
| 20 |
|
| 21 |
import android.annotation.NonNull; |
| 22 |
import android.net.ipsec.ike.IkeSaProposal; |
| 23 |
import android.os.PersistableBundle; |
| 24 |
|
| 25 |
import com.android.internal.annotations.VisibleForTesting; |
| 26 |
import com.android.server.vcn.util.PersistableBundleUtils; |
| 27 |
|
| 28 |
import java.util.List; |
| 29 |
import java.util.Objects; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
@VisibleForTesting(visibility = Visibility.PRIVATE) |
| 37 |
public final class IkeSaProposalUtils extends SaProposalUtilsBase { |
| 38 |
private static final String PRF_KEY = "PRF_KEY"; |
| 39 |
|
| 40 |
|
| 41 |
@NonNull |
| 42 |
public static PersistableBundle toPersistableBundle(IkeSaProposal proposal) { |
| 43 |
final PersistableBundle result = SaProposalUtilsBase.toPersistableBundle(proposal); |
| 44 |
|
| 45 |
final int[] prfArray = |
| 46 |
proposal.getPseudorandomFunctions().stream().mapToInt(i -> i).toArray(); |
| 47 |
result.putIntArray(PRF_KEY, prfArray); |
| 48 |
|
| 49 |
return result; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
@NonNull |
| 54 |
public static IkeSaProposal fromPersistableBundle(@NonNull PersistableBundle in) { |
| 55 |
Objects.requireNonNull(in, "PersistableBundle was null"); |
| 56 |
|
| 57 |
final IkeSaProposal.Builder builder = new IkeSaProposal.Builder(); |
| 58 |
|
| 59 |
final PersistableBundle encryptionBundle = in.getPersistableBundle(ENCRYPT_ALGO_KEY); |
| 60 |
Objects.requireNonNull(encryptionBundle, "Encryption algo bundle was null"); |
| 61 |
final List<EncryptionAlgoKeyLenPair> encryptList = |
| 62 |
PersistableBundleUtils.toList(encryptionBundle, EncryptionAlgoKeyLenPair::new); |
| 63 |
for (EncryptionAlgoKeyLenPair t : encryptList) { |
| 64 |
builder.addEncryptionAlgorithm(t.encryptionAlgo, t.keyLen); |
| 65 |
} |
| 66 |
|
| 67 |
final int[] integrityAlgoIdArray = in.getIntArray(INTEGRITY_ALGO_KEY); |
| 68 |
Objects.requireNonNull(integrityAlgoIdArray, "Integrity algo array was null"); |
| 69 |
for (int algo : integrityAlgoIdArray) { |
| 70 |
builder.addIntegrityAlgorithm(algo); |
| 71 |
} |
| 72 |
|
| 73 |
final int[] dhGroupArray = in.getIntArray(DH_GROUP_KEY); |
| 74 |
Objects.requireNonNull(dhGroupArray, "DH Group array was null"); |
| 75 |
for (int dh : dhGroupArray) { |
| 76 |
builder.addDhGroup(dh); |
| 77 |
} |
| 78 |
|
| 79 |
final int[] prfArray = in.getIntArray(PRF_KEY); |
| 80 |
Objects.requireNonNull(prfArray, "PRF array was null"); |
| 81 |
for (int prf : prfArray) { |
| 82 |
builder.addPseudorandomFunction(prf); |
| 83 |
} |
| 84 |
|
| 85 |
return builder.build(); |
| 86 |
} |
| 87 |
} |