Skip to content

Commit 0f1ee30

Browse files
Merge pull request #84 from godaddy/fix-estimate-buffer-base64
Fix EstimateBuffer base64 size calculation
2 parents 9d0dbbe + 6c4d358 commit 0f1ee30

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

constants.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ const ERR_PANIC = -106
1010

1111
const EstimatedEncryptionOverhead = 48
1212
const EstimatedEnvelopeOverhead = 185
13-
const Base64Overhead = 1.34

libasherah.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ func SetupJson(configJson unsafe.Pointer) (result int32) {
118118

119119
//export EstimateBuffer
120120
func EstimateBuffer(dataLen int32, partitionLen int32) int32 {
121-
estimatedDataLen := float64(dataLen+EstimatedEncryptionOverhead) * Base64Overhead
122-
result := int32(cobhan.BUFFER_HEADER_SIZE + EstimatedEnvelopeOverhead + EstimatedIntermediateKeyOverhead + int(partitionLen) + int(estimatedDataLen))
121+
estimatedDataLen := ((int(dataLen) + EstimatedEncryptionOverhead + 2) / 3) * 4
122+
result := int32(cobhan.BUFFER_HEADER_SIZE + EstimatedEnvelopeOverhead + EstimatedIntermediateKeyOverhead + int(partitionLen) + estimatedDataLen)
123123
return result
124124
}
125125

0 commit comments

Comments
 (0)