OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 // Original code is licensed as follows: | 6 // Original code is licensed as follows: |
7 /* | 7 /* |
8 * Copyright 2006-2007 Jeremias Maerki. | 8 * Copyright 2006-2007 Jeremias Maerki. |
9 * | 9 * |
10 * Licensed under the Apache License, Version 2.0 (the "License"); | 10 * Licensed under the Apache License, Version 2.0 (the "License"); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 FX_CHAR buf[128]; | 51 FX_CHAR buf[128]; |
52 FXSYS_itoa(dataCount, buf, 10); | 52 FXSYS_itoa(dataCount, buf, 10); |
53 buffer.SetAt(0, FX_WCHAR(*buf) - '0'); | 53 buffer.SetAt(0, FX_WCHAR(*buf) - '0'); |
54 int32_t lengthFieldSize = 1; | 54 int32_t lengthFieldSize = 1; |
55 int32_t currentSize = | 55 int32_t currentSize = |
56 context.getCodewordCount() + dataCount + lengthFieldSize; | 56 context.getCodewordCount() + dataCount + lengthFieldSize; |
57 context.updateSymbolInfo(currentSize, e); | 57 context.updateSymbolInfo(currentSize, e); |
58 if (e != BCExceptionNO) { | 58 if (e != BCExceptionNO) { |
59 return; | 59 return; |
60 } | 60 } |
61 FX_BOOL mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0; | 61 bool mustPad = (context.m_symbolInfo->m_dataCapacity - currentSize) > 0; |
62 if (context.hasMoreCharacters() || mustPad) { | 62 if (context.hasMoreCharacters() || mustPad) { |
63 if (dataCount <= 249) { | 63 if (dataCount <= 249) { |
64 buffer.SetAt(0, (FX_WCHAR)dataCount); | 64 buffer.SetAt(0, (FX_WCHAR)dataCount); |
65 } else if (dataCount > 249 && dataCount <= 1555) { | 65 } else if (dataCount > 249 && dataCount <= 1555) { |
66 buffer.SetAt(0, (FX_WCHAR)((dataCount / 250) + 249)); | 66 buffer.SetAt(0, (FX_WCHAR)((dataCount / 250) + 249)); |
67 buffer.Insert(1, (FX_WCHAR)(dataCount % 250)); | 67 buffer.Insert(1, (FX_WCHAR)(dataCount % 250)); |
68 } else { | 68 } else { |
69 e = BCExceptionIllegalStateMessageLengthInvalid; | 69 e = BCExceptionIllegalStateMessageLengthInvalid; |
70 return; | 70 return; |
71 } | 71 } |
72 } | 72 } |
73 for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) { | 73 for (int32_t i = 0, c = buffer.GetLength(); i < c; i++) { |
74 context.writeCodeword( | 74 context.writeCodeword( |
75 randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1)); | 75 randomize255State(buffer.GetAt(i), context.getCodewordCount() + 1)); |
76 } | 76 } |
77 } | 77 } |
78 FX_WCHAR CBC_Base256Encoder::randomize255State(FX_WCHAR ch, | 78 FX_WCHAR CBC_Base256Encoder::randomize255State(FX_WCHAR ch, |
79 int32_t codewordPosition) { | 79 int32_t codewordPosition) { |
80 int32_t pseudoRandom = ((149 * codewordPosition) % 255) + 1; | 80 int32_t pseudoRandom = ((149 * codewordPosition) % 255) + 1; |
81 int32_t tempVariable = ch + pseudoRandom; | 81 int32_t tempVariable = ch + pseudoRandom; |
82 if (tempVariable <= 255) { | 82 if (tempVariable <= 255) { |
83 return (FX_WCHAR)tempVariable; | 83 return (FX_WCHAR)tempVariable; |
84 } else { | 84 } else { |
85 return (FX_WCHAR)(tempVariable - 256); | 85 return (FX_WCHAR)(tempVariable - 256); |
86 } | 86 } |
87 } | 87 } |
OLD | NEW |