pwd_util.c 892 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2009 Red Hat, Inc.
  3. * All rights reserved.
  4. *
  5. * License: GPL (version 3 or any later version).
  6. * See LICENSE for details.
  7. * END COPYRIGHT BLOCK **/
  8. #ifdef HAVE_CONFIG_H
  9. # include <config.h>
  10. #endif
  11. #include <string.h>
  12. #include "pwdstorage.h"
  13. /*
  14. * Utility functions for the Password Storage Scheme plugins.
  15. */
  16. /*
  17. * calculate the number of bytes the base64 encoded encval
  18. * will have when decoded, taking into account padding
  19. */
  20. PRUint32
  21. pwdstorage_base64_decode_len(const char *encval, PRUint32 enclen)
  22. {
  23. PRUint32 len = enclen;
  24. if (len == 0) {
  25. len = strlen(encval);
  26. }
  27. if (len && (0 == (len & 3))) {
  28. if('=' == encval[len - 1]) {
  29. if('=' == encval[len - 2]) {
  30. len -= 2;
  31. } else {
  32. len -= 1;
  33. }
  34. }
  35. }
  36. return ((len * 3) / 4);
  37. }