public override int encodeInteger(object obj, System.IO.Stream stream, ElementInfo elementInfo) { int result = 0; bool hasConstraint = false; long min = 0, max = 0; if (elementInfo.hasPreparedInfo()) { if (elementInfo.PreparedInfo.hasConstraint() && elementInfo.PreparedInfo.Constraint is ASN1ValueRangeConstraintMetadata) { IASN1ConstraintMetadata constraint = elementInfo.PreparedInfo.Constraint; hasConstraint = true; min = ((ASN1ValueRangeConstraintMetadata)constraint).Min; max = ((ASN1ValueRangeConstraintMetadata)constraint).Max; } } else if (elementInfo.isAttributePresent <ASN1ValueRangeConstraint>()) { hasConstraint = true; ASN1ValueRangeConstraint constraint = elementInfo.getAttribute <ASN1ValueRangeConstraint>(); min = constraint.Min; max = constraint.Max; } if (obj.GetType().Equals(typeof(int))) { int val = (int)obj; BitArrayOutputStream bitStream = (BitArrayOutputStream)stream; if (hasConstraint) { result += encodeConstraintNumber(val, min, max, bitStream); } else { result += encodeUnconstraintNumber(val, bitStream); } } else { long val = (long)obj; BitArrayOutputStream bitStream = (BitArrayOutputStream)stream; if (hasConstraint) { result += encodeConstraintNumber(val, min, max, bitStream); } else { result += encodeUnconstraintNumber(val, bitStream); } } return(result); }
private void setupConstraint(ICustomAttributeProvider annotated) { if (CoderUtils.isAttributePresent <ASN1SizeConstraint>(annotated)) { constraint = new ASN1SizeConstraintMetadata(CoderUtils.getAttribute <ASN1SizeConstraint>(annotated)); } else if (CoderUtils.isAttributePresent <ASN1ValueRangeConstraint>(annotated)) { constraint = new ASN1ValueRangeConstraintMetadata(CoderUtils.getAttribute <ASN1ValueRangeConstraint>(annotated)); } }
protected int encodeLength(int val, ElementInfo elementInfo, System.IO.Stream stream) { CoderUtils.checkConstraints(val, elementInfo); int resultSize = 0; BitArrayOutputStream bitStream = (BitArrayOutputStream)stream; if (elementInfo.hasPreparedInfo()) { if (elementInfo.PreparedInfo.hasConstraint()) { IASN1ConstraintMetadata constraint = elementInfo.PreparedInfo.Constraint; if (constraint is ASN1ValueRangeConstraintMetadata) { resultSize += encodeConstraintLengthDeterminant( val, (int)((ASN1ValueRangeConstraintMetadata)constraint).Min, (int)((ASN1ValueRangeConstraintMetadata)constraint).Max, bitStream ); } else if (constraint is ASN1SizeConstraintMetadata) { } } else { resultSize += encodeLengthDeterminant(val, bitStream); } } else { if (elementInfo.isAttributePresent <ASN1ValueRangeConstraint>()) { ASN1ValueRangeConstraint constraint = elementInfo.getAttribute <ASN1ValueRangeConstraint>(); resultSize += encodeConstraintLengthDeterminant(val, (int)constraint.Min, (int)constraint.Max, bitStream); } else if (elementInfo.isAttributePresent <ASN1SizeConstraint>()) { ASN1SizeConstraint constraint = elementInfo.getAttribute <ASN1SizeConstraint>(); } else { resultSize += encodeLengthDeterminant(val, bitStream); } } return(resultSize); }
protected virtual int decodeLength(ElementInfo elementInfo, System.IO.Stream stream) { int result = 0; BitArrayInputStream bitStream = (BitArrayInputStream)stream; if (elementInfo.hasPreparedInfo()) { if (elementInfo.PreparedInfo.hasConstraint()) { IASN1ConstraintMetadata constraint = elementInfo.PreparedInfo.Constraint; if (constraint is ASN1ValueRangeConstraintMetadata) { result = decodeConstraintLengthDeterminant( (int)((ASN1ValueRangeConstraintMetadata)constraint).Min, (int)((ASN1ValueRangeConstraintMetadata)constraint).Max, bitStream ); } else if (constraint is ASN1SizeConstraintMetadata) { result = (int)((ASN1SizeConstraintMetadata)constraint).Max; } } else { result = decodeLengthDeterminant(bitStream); } } else if (elementInfo.isAttributePresent <ASN1ValueRangeConstraint>()) { ASN1ValueRangeConstraint constraint = elementInfo.getAttribute <ASN1ValueRangeConstraint>(); result = decodeConstraintLengthDeterminant((int)constraint.Min, (int)constraint.Max, bitStream); } else if (elementInfo.isAttributePresent <ASN1SizeConstraint>()) { ASN1SizeConstraint constraint = elementInfo.getAttribute <ASN1SizeConstraint>(); result = (int)constraint.Max; } else { result = decodeLengthDeterminant(bitStream); } CoderUtils.checkConstraints(result, elementInfo); return(result); }
public override DecodedObject <object> decodeInteger(DecodedObject <object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream) { bool hasConstraint = false; long min = 0, max = 0; if (elementInfo.hasPreparedInfo()) { if (elementInfo.PreparedInfo.hasConstraint() && elementInfo.PreparedInfo.Constraint is ASN1ValueRangeConstraintMetadata) { IASN1ConstraintMetadata constraint = elementInfo.PreparedInfo.Constraint; hasConstraint = true; min = ((ASN1ValueRangeConstraintMetadata)constraint).Min; max = ((ASN1ValueRangeConstraintMetadata)constraint).Max; } } else if (elementInfo.isAttributePresent <ASN1ValueRangeConstraint>()) { hasConstraint = true; ASN1ValueRangeConstraint constraint = elementInfo.getAttribute <ASN1ValueRangeConstraint>(); min = constraint.Min; max = constraint.Max; } DecodedObject <object> result = new DecodedObject <object>(); BitArrayInputStream bitStream = (BitArrayInputStream)stream; int val = 0; if (hasConstraint) { ASN1ValueRangeConstraint constraint = elementInfo.getAttribute <ASN1ValueRangeConstraint>(); val = (int)decodeConstraintNumber(min, max, bitStream); } else { val = decodeUnconstraintNumber(bitStream); } result.Value = val; return(result); }
private void setupConstraint(ICustomAttributeProvider annotated) { if( CoderUtils.isAttributePresent<ASN1SizeConstraint>(annotated) ) { constraint = new ASN1SizeConstraintMetadata( CoderUtils.getAttribute<ASN1SizeConstraint> (annotated) ) ; } else if (CoderUtils.isAttributePresent<ASN1ValueRangeConstraint>(annotated)) { constraint = new ASN1ValueRangeConstraintMetadata(CoderUtils.getAttribute<ASN1ValueRangeConstraint>(annotated)); } }