1 package org.bouncycastle.cms; 2 3 import java.io.InputStream; 4 5 import org.bouncycastle.asn1.x509.AlgorithmIdentifier; 6 import org.bouncycastle.operator.InputDecryptor; 7 import org.bouncycastle.operator.MacCalculator; 8 import org.bouncycastle.util.io.TeeInputStream; 9 10 public class RecipientOperator 11 { 12 private final AlgorithmIdentifier algorithmIdentifier; 13 private final Object operator; 14 RecipientOperator(InputDecryptor decryptor)15 public RecipientOperator(InputDecryptor decryptor) 16 { 17 this.algorithmIdentifier = decryptor.getAlgorithmIdentifier(); 18 this.operator = decryptor; 19 } 20 RecipientOperator(MacCalculator macCalculator)21 public RecipientOperator(MacCalculator macCalculator) 22 { 23 this.algorithmIdentifier = macCalculator.getAlgorithmIdentifier(); 24 this.operator = macCalculator; 25 } 26 getInputStream(InputStream dataIn)27 public InputStream getInputStream(InputStream dataIn) 28 { 29 if (operator instanceof InputDecryptor) 30 { 31 return ((InputDecryptor)operator).getInputStream(dataIn); 32 } 33 else 34 { 35 return new TeeInputStream(dataIn, ((MacCalculator)operator).getOutputStream()); 36 } 37 } 38 isMacBased()39 public boolean isMacBased() 40 { 41 return operator instanceof MacCalculator; 42 } 43 getMac()44 public byte[] getMac() 45 { 46 return ((MacCalculator)operator).getMac(); 47 } 48 } 49