All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.amazonaws.encryptionsdk.CommitmentPolicy Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.amazonaws.encryptionsdk;

import com.amazonaws.encryptionsdk.CryptoAlgorithm;

public enum CommitmentPolicy {
    ForbidEncryptAllowDecrypt,
    RequireEncryptAllowDecrypt,
    RequireEncryptRequireDecrypt;

    public boolean algorithmAllowedForEncrypt(CryptoAlgorithm algorithm) {
        switch (this) {
            case ForbidEncryptAllowDecrypt:
                return !algorithm.isCommitting();
            case RequireEncryptAllowDecrypt:
            case RequireEncryptRequireDecrypt:
                return algorithm.isCommitting();
            default:
                throw new UnsupportedOperationException("Support for commitment policy " + this + " not yet built.");
        }
    }

    public boolean algorithmAllowedForDecrypt(CryptoAlgorithm algorithm) {
        switch (this) {
            case ForbidEncryptAllowDecrypt:
            case RequireEncryptAllowDecrypt:
                return true;
            case RequireEncryptRequireDecrypt:
                return algorithm.isCommitting();
            default:
                throw new UnsupportedOperationException("Support for commitment policy " + this + " not yet built.");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy