Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
1.9 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. base64.h
  5. Abstract:
  6. base64
  7. Author:
  8. Larry Zhu (LZhu) December 1, 2001 Created
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #ifndef __BASE64_H__
  14. #define __BASE64_H__
  15. #include <assert.h>
  16. #ifdef UNICODE
  17. #define Base64Encode Base64EncodeW
  18. #else
  19. #define Base64Encode Base64EncodeA
  20. #endif // !UNICODE
  21. #ifndef SAFE_SUBTRACT_POINTERS
  22. #define SAFE_SUBTRACT_POINTERS(__x__, __y__) ( DW_PtrDiffc(__x__, sizeof(*(__x__)), __y__, sizeof(*(__y__))) )
  23. #define CRYPT_STRING_NOCR 0x80000000
  24. __inline DWORD
  25. DW_PtrDiffc(
  26. IN void const *pb1,
  27. IN DWORD dwPtrEltSize1,
  28. IN void const *pb2,
  29. IN DWORD dwPtrEltSize2)
  30. {
  31. // pb1 should be greater
  32. assert((ULONG_PTR)pb1 >= (ULONG_PTR)pb2);
  33. // both should have same elt size
  34. assert(dwPtrEltSize1 == dwPtrEltSize2);
  35. // assert that the result doesn't overflow 32-bits
  36. assert((DWORD)((ULONG_PTR)pb1 - (ULONG_PTR)pb2) == (ULONG_PTR)((ULONG_PTR)pb1 - (ULONG_PTR)pb2));
  37. // return number of objects between these pointers
  38. return (DWORD) ( ((ULONG_PTR)pb1 - (ULONG_PTR)pb2) / dwPtrEltSize1 );
  39. }
  40. #endif SAFE_SUBTRACT_POINTERS
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. DWORD
  45. Base64DecodeA(
  46. IN CHAR const *pchIn,
  47. IN DWORD cchIn,
  48. OPTIONAL OUT BYTE *pbOut,
  49. IN OUT DWORD *pcbOut
  50. );
  51. DWORD
  52. Base64EncodeA(
  53. IN BYTE const *pbIn,
  54. IN DWORD cbIn,
  55. IN DWORD Flags,
  56. OPTIONAL OUT CHAR *pchOut,
  57. IN OUT DWORD *pcchOut
  58. );
  59. DWORD
  60. Base64EncodeW(
  61. IN BYTE const *pbIn,
  62. IN DWORD cbIn,
  63. IN DWORD Flags,
  64. OUT WCHAR *wszOut,
  65. OUT DWORD *pcchOut
  66. );
  67. DWORD
  68. Base64DecodeW(
  69. IN const WCHAR * wszIn,
  70. IN DWORD cch,
  71. OUT BYTE *pbOut,
  72. OUT DWORD *pcbOut
  73. );
  74. #ifdef __cplusplus
  75. }
  76. #endif
  77. #endif // #ifndef __BASE64_H__