| 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.ChildSaProposal; |
| 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 ChildSaProposalUtils extends SaProposalUtilsBase { |
| 38 |
|
| 39 |
@NonNull |
| 40 |
public static PersistableBundle toPersistableBundle(ChildSaProposal proposal) { |
| 41 |
return SaProposalUtilsBase.toPersistableBundle(proposal); |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
@NonNull |
| 46 |
public static ChildSaProposal fromPersistableBundle(@NonNull PersistableBundle in) { |
| 47 |
Objects.requireNonNull(in, "PersistableBundle was null"); |
| 48 |
|
| 49 |
final ChildSaProposal.Builder builder = new ChildSaProposal.Builder(); |
| 50 |
|
| 51 |
final PersistableBundle encryptionBundle = in.getPersistableBundle(ENCRYPT_ALGO_KEY); |
| 52 |
Objects.requireNonNull(encryptionBundle, "Encryption algo bundle was null"); |
| 53 |
final List<EncryptionAlgoKeyLenPair> encryptList = |
| 54 |
PersistableBundleUtils.toList(encryptionBundle, EncryptionAlgoKeyLenPair::new); |
| 55 |
for (EncryptionAlgoKeyLenPair t : encryptList) { |
| 56 |
builder.addEncryptionAlgorithm(t.encryptionAlgo, t.keyLen); |
| 57 |
} |
| 58 |
|
| 59 |
final int[] integrityAlgoIdArray = in.getIntArray(INTEGRITY_ALGO_KEY); |
| 60 |
Objects.requireNonNull(integrityAlgoIdArray, "Integrity algo array was null"); |
| 61 |
for (int algo : integrityAlgoIdArray) { |
| 62 |
builder.addIntegrityAlgorithm(algo); |
| 63 |
} |
| 64 |
|
| 65 |
final int[] dhGroupArray = in.getIntArray(DH_GROUP_KEY); |
| 66 |
Objects.requireNonNull(dhGroupArray, "DH Group array was null"); |
| 67 |
for (int dh : dhGroupArray) { |
| 68 |
builder.addDhGroup(dh); |
| 69 |
} |
| 70 |
|
| 71 |
return builder.build(); |
| 72 |
} |
| 73 |
} |