<commit_before>/*
    kpgpblock.cpp

    Copyright (C) 2001,2002 the KPGP authors
    See file AUTHORS.kpgp for details

    This file is part of KPGP, the KDE PGP/GnuPG support library.

    KPGP is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 */

#include "kpgpblock.h"
#include "kpgp.h"

#include <string.h>

namespace Kpgp {

Block::Block( const QCString& str )
  : mText(str), mProcessedText(), mError(),
    mSignatureUserId(), mSignatureKeyId(), mSignatureDate(),
    mRequiredKey(), mEncryptedFor(),
    mStatus(0), mHasBeenProcessed(false), mType(NoPgpBlock)
{
  mEncryptedFor.setAutoDelete( true );
}

Block::~Block()
{
}

void
Block::reset()
{
  mProcessedText = QCString();
  mError = QCString();
  mSignatureUserId = QString::null;
  mSignatureKeyId = QCString();
  mSignatureDate = QCString();
  mRequiredKey = QCString();
  mEncryptedFor.clear();
  mStatus = 0;
  mHasBeenProcessed = false;
}

void
Block::clear()
{
  reset();
  mText = QCString();
  mType = NoPgpBlock;
}

BlockType
Block::determineType() const
{
  if( !strncmp( mText.data(), "-----BEGIN PGP ", 15 ) )
  {
    if( !strncmp( mText.data() + 15, "SIGNED", 6 ) )
      return ClearsignedBlock;
    else if( !strncmp( mText.data() + 15, "SIGNATURE", 9 ) )
      return SignatureBlock;
    else if( !strncmp( mText.data() + 15, "PUBLIC", 6 ) )
      return PublicKeyBlock;
    else if( !strncmp( mText.data() + 15, "PRIVATE", 7 ) ||
             !strncmp( mText.data() + 15, "SECRET", 6 ) )
      return PrivateKeyBlock;
    else if( !strncmp( mText.data() + 15, "MESSAGE", 7 ) )
    {
      if( !strncmp( mText.data() + 22, ", PART", 6 ) )
        return MultiPgpMessageBlock;
      else
        return PgpMessageBlock;
    }
    else
      return UnknownBlock;
  }
  else
    return NoPgpBlock;
}

bool
Block::decrypt()<commit_msg>Decrypt PEM ( Privacy Enchanced Mail ) too. Approved by <NAME>. Patch by <NAME> . CCMAIL: <EMAIL><commit_after>/*
    kpgpblock.cpp

    Copyright (C) 2001,2002 the KPGP authors
    See file AUTHORS.kpgp for details

    This file is part of KPGP, the KDE PGP/GnuPG support library.

    KPGP is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA
 */

#include "kpgpblock.h"
#include "kpgp.h"

#include <string.h>

namespace Kpgp {

Block::Block( const QCString& str )
  : mText(str), mProcessedText(), mError(),
    mSignatureUserId(), mSignatureKeyId(), mSignatureDate(),
    mRequiredKey(), mEncryptedFor(),
    mStatus(0), mHasBeenProcessed(false), mType(NoPgpBlock)
{
  mEncryptedFor.setAutoDelete( true );
}

Block::~Block()
{
}

void
Block::reset()
{
  mProcessedText = QCString();
  mError = QCString();
  mSignatureUserId = QString::null;
  mSignatureKeyId = QCString();
  mSignatureDate = QCString();
  mRequiredKey = QCString();
  mEncryptedFor.clear();
  mStatus = 0;
  mHasBeenProcessed = false;
}

void
Block::clear()
{
  reset();
  mText = QCString();
  mType = NoPgpBlock;
}

BlockType
Block::determineType() const
{
  if( !strncmp( mText.data(), "-----BEGIN PGP ", 15 ) )
  {
    if( !strncmp( mText.data() + 15, "SIGNED", 6 ) )
      return ClearsignedBlock;
    else if( !strncmp( mText.data() + 15, "SIGNATURE", 9 ) )
      return SignatureBlock;
    else if( !strncmp( mText.data() + 15, "PUBLIC", 6 ) )
      return PublicKeyBlock;
    else if( !strncmp( mText.data() + 15, "PRIVATE", 7 ) ||
             !strncmp( mText.data() + 15, "SECRET", 6 ) )
      return PrivateKeyBlock;
    else if( !strncmp( mText.data() + 15, "MESSAGE", 7 ) )
    {
      if( !strncmp( mText.data() + 22, ", PART", 6 ) )
        return MultiPgpMessageBlock;
      else
        return PgpMessageBlock;
    }
    else if( !strncmp( mText.data() + 15, "ARMORED FILE", 12 ) )
      return PgpMessageBlock;
    else
      return UnknownBlock;
  }
  else
    return NoPgpBlock;
}

bool
Block::decrypt()
{'fraction_non_alphanumeric': 0.12703230002167787, 'fraction_numerical': 0.021677866897897247, 'mean_word_length': 3.2408088235294117, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2332047', 'n_tokens_mistral': 1677, 'n_tokens_neox': 1564, 'n_words': 472}