~ps-jenkins/clickmanager-plugin/latestsnapshot-0.1+13.10.20131003.1-0ubuntu1

« back to all changes in this revision

Viewing changes to download/hash_algorithm.cpp

  • Committer: Diego Sarmentero
  • Date: 2013-09-11 16:55:11 UTC
  • Revision ID: diego.sarmentero@gmail.com-20130911165511-o2h2tpzk110rqu8c
adding missing files for the new download manager api

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of version 3 of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public
 
14
 * License along with this library; if not, write to the
 
15
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
 * Boston, MA 02110-1301, USA.
 
17
 */
 
18
 
 
19
#include "./hash_algorithm.h"
 
20
 
 
21
QCryptographicHash::Algorithm
 
22
HashAlgorithm::getHashAlgo(const QString& algorithm) {
 
23
    // lowercase the algorithm just in case
 
24
    QString algoLower = algorithm.toLower();
 
25
    QCryptographicHash::Algorithm algo = QCryptographicHash::Md5;
 
26
 
 
27
    if (algoLower == "md5")
 
28
        algo = QCryptographicHash::Md5;
 
29
    else if (algoLower == "sha1")
 
30
        algo = QCryptographicHash::Sha1;
 
31
    else if (algoLower == "sha224")
 
32
        algo = QCryptographicHash::Sha224;
 
33
    else if (algoLower == "sha256")
 
34
        algo = QCryptographicHash::Sha256;
 
35
    else if (algoLower == "sha384")
 
36
        algo = QCryptographicHash::Sha384;
 
37
    else if (algoLower == "sha512")
 
38
        algo = QCryptographicHash::Sha512;
 
39
    else
 
40
        algo = QCryptographicHash::Md5;
 
41
    return algo;
 
42
}
 
43
 
 
44
QString
 
45
HashAlgorithm::getHashAlgo(QCryptographicHash::Algorithm algorithm) {
 
46
    switch (algorithm) {
 
47
        case QCryptographicHash::Md5:
 
48
            return "md5";
 
49
        case QCryptographicHash::Sha1:
 
50
            return "sha1";
 
51
        case QCryptographicHash::Sha224:
 
52
            return "sha224";
 
53
        case QCryptographicHash::Sha256:
 
54
            return "shq256";
 
55
        case QCryptographicHash::Sha384:
 
56
            return "sha384";
 
57
        case QCryptographicHash::Sha512:
 
58
            return "sha512";
 
59
        default:
 
60
            return "";
 
61
    }
 
62
}