void Message::Clear() { if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (has_to()) { if (to_ != &::google::protobuf::internal::kEmptyString) { to_->clear(); } } id_ = GOOGLE_LONGLONG(0); time_ = GOOGLE_LONGLONG(0); if (has_from()) { if (from_ != &::google::protobuf::internal::kEmptyString) { from_->clear(); } } type_ = 0; if (has_sn()) { if (sn_ != &::google::protobuf::internal::kEmptyString) { sn_->clear(); } } if (has_data()) { if (data_ != &::google::protobuf::internal::kEmptyString) { data_->clear(); } } expire_ = GOOGLE_LONGLONG(0); } ::memset(_has_bits_, 0, sizeof(_has_bits_)); }
void Message::SerializeWithCachedSizes( ::google::protobuf::io::CodedOutputStream* output) const { // optional string to = 1; if (has_to()) { ::google::protobuf::internal::WireFormatLite::WriteString( 1, this->to(), output); } // optional int64 id = 2; if (has_id()) { ::google::protobuf::internal::WireFormatLite::WriteInt64(2, this->id(), output); } // optional int64 time = 3; if (has_time()) { ::google::protobuf::internal::WireFormatLite::WriteInt64(3, this->time(), output); } // optional string from = 4; if (has_from()) { ::google::protobuf::internal::WireFormatLite::WriteString( 4, this->from(), output); } // optional int32 type = 5; if (has_type()) { ::google::protobuf::internal::WireFormatLite::WriteInt32(5, this->type(), output); } // optional string sn = 6; if (has_sn()) { ::google::protobuf::internal::WireFormatLite::WriteString( 6, this->sn(), output); } // optional bytes data = 7; if (has_data()) { ::google::protobuf::internal::WireFormatLite::WriteBytes( 7, this->data(), output); } // optional int64 expire = 8; if (has_expire()) { ::google::protobuf::internal::WireFormatLite::WriteInt64(8, this->expire(), output); } }
/* Note: When in ephemeral mode the search function does visit all blobs but in standard mode, blobs flagged as ephemeral are ignored. */ int keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc) { int rc; size_t n; int need_words, any_skip; KEYBOXBLOB blob = NULL; struct sn_array_s *sn_array = NULL; if (!hd) return gpg_error (GPG_ERR_INV_VALUE); /* clear last found result */ if (hd->found.blob) { _keybox_release_blob (hd->found.blob); hd->found.blob = NULL; } if (hd->error) return hd->error; /* still in error state */ if (hd->eof) return -1; /* still EOF */ /* figure out what information we need */ need_words = any_skip = 0; for (n=0; n < ndesc; n++) { switch (desc[n].mode) { case KEYDB_SEARCH_MODE_WORDS: need_words = 1; break; case KEYDB_SEARCH_MODE_FIRST: /* always restart the search in this mode */ keybox_search_reset (hd); break; default: break; } if (desc[n].skipfnc) any_skip = 1; if (desc[n].snlen == -1 && !sn_array) { sn_array = xtrycalloc (ndesc, sizeof *sn_array); if (!sn_array) return (hd->error = gpg_error_from_syserror ()); } } (void)need_words; /* Not yet implemented. */ if (!hd->fp) { hd->fp = fopen (hd->kb->fname, "rb"); if (!hd->fp) { hd->error = gpg_error_from_syserror (); xfree (sn_array); return hd->error; } } /* Kludge: We need to convert an SN given as hexstring to its binary representation - in some cases we are not able to store it in the search descriptor, because due to the way we use it, it is not possible to free allocated memory. */ if (sn_array) { const unsigned char *s; int i, odd; size_t snlen; for (n=0; n < ndesc; n++) { if (!desc[n].sn) ; else if (desc[n].snlen == -1) { unsigned char *sn; s = desc[n].sn; for (i=0; *s && *s != '/'; s++, i++) ; odd = (i & 1); snlen = (i+1)/2; sn_array[n].sn = xtrymalloc (snlen); if (!sn_array[n].sn) { hd->error = gpg_error_from_syserror (); release_sn_array (sn_array, n); return hd->error; } sn_array[n].snlen = snlen; sn = sn_array[n].sn; s = desc[n].sn; if (odd) { *sn++ = xtoi_1 (s); s++; } for (; *s && *s != '/'; s += 2) *sn++ = xtoi_2 (s); } else { const unsigned char *sn; sn = desc[n].sn; snlen = desc[n].snlen; sn_array[n].sn = xtrymalloc (snlen); if (!sn_array[n].sn) { hd->error = gpg_error_from_syserror (); release_sn_array (sn_array, n); return hd->error; } sn_array[n].snlen = snlen; memcpy (sn_array[n].sn, sn, snlen); } } } for (;;) { unsigned int blobflags; _keybox_release_blob (blob); blob = NULL; rc = _keybox_read_blob (&blob, hd->fp); if (rc) break; if (blob_get_type (blob) == BLOBTYPE_HEADER) continue; blobflags = blob_get_blob_flags (blob); if (!hd->ephemeral && (blobflags & 2)) continue; /* Not in ephemeral mode but blob is flagged ephemeral. */ for (n=0; n < ndesc; n++) { switch (desc[n].mode) { case KEYDB_SEARCH_MODE_NONE: never_reached (); break; case KEYDB_SEARCH_MODE_EXACT: if (has_subject_or_alt (blob, desc[n].u.name, 0)) goto found; break; case KEYDB_SEARCH_MODE_MAIL: if (has_mail (blob, desc[n].u.name, 0)) goto found; break; case KEYDB_SEARCH_MODE_MAILSUB: if (has_mail (blob, desc[n].u.name, 1)) goto found; break; case KEYDB_SEARCH_MODE_SUBSTR: if (has_subject_or_alt (blob, desc[n].u.name, 1)) goto found; break; case KEYDB_SEARCH_MODE_MAILEND: case KEYDB_SEARCH_MODE_WORDS: never_reached (); /* not yet implemented */ break; case KEYDB_SEARCH_MODE_ISSUER: if (has_issuer (blob, desc[n].u.name)) goto found; break; case KEYDB_SEARCH_MODE_ISSUER_SN: if (has_issuer_sn (blob, desc[n].u.name, sn_array? sn_array[n].sn : desc[n].sn, sn_array? sn_array[n].snlen : desc[n].snlen)) goto found; break; case KEYDB_SEARCH_MODE_SN: if (has_sn (blob, sn_array? sn_array[n].sn : desc[n].sn, sn_array? sn_array[n].snlen : desc[n].snlen)) goto found; break; case KEYDB_SEARCH_MODE_SUBJECT: if (has_subject (blob, desc[n].u.name)) goto found; break; case KEYDB_SEARCH_MODE_SHORT_KID: if (has_short_kid (blob, desc[n].u.kid[1])) goto found; break; case KEYDB_SEARCH_MODE_LONG_KID: if (has_long_kid (blob, desc[n].u.kid[0], desc[n].u.kid[1])) goto found; break; case KEYDB_SEARCH_MODE_FPR: case KEYDB_SEARCH_MODE_FPR20: if (has_fingerprint (blob, desc[n].u.fpr)) goto found; break; case KEYDB_SEARCH_MODE_KEYGRIP: if (has_keygrip (blob, desc[n].u.grip)) goto found; break; case KEYDB_SEARCH_MODE_FIRST: goto found; break; case KEYDB_SEARCH_MODE_NEXT: goto found; break; default: rc = gpg_error (GPG_ERR_INV_VALUE); goto found; } } continue; found: for (n=any_skip?0:ndesc; n < ndesc; n++) { /* if (desc[n].skipfnc */ /* && desc[n].skipfnc (desc[n].skipfncvalue, aki, NULL)) */ /* break; */ } if (n == ndesc) break; /* got it */ } if (!rc) { hd->found.blob = blob; } else if (rc == -1) { _keybox_release_blob (blob); hd->eof = 1; } else { _keybox_release_blob (blob); hd->error = rc; } if (sn_array) release_sn_array (sn_array, ndesc); return rc; }
int Message::ByteSize() const { int total_size = 0; if (_has_bits_[0 / 32] & (0xffu << (0 % 32))) { // optional string to = 1; if (has_to()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->to()); } // optional int64 id = 2; if (has_id()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int64Size( this->id()); } // optional int64 time = 3; if (has_time()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int64Size( this->time()); } // optional string from = 4; if (has_from()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->from()); } // optional int32 type = 5; if (has_type()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int32Size( this->type()); } // optional string sn = 6; if (has_sn()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize( this->sn()); } // optional bytes data = 7; if (has_data()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::BytesSize( this->data()); } // optional int64 expire = 8; if (has_expire()) { total_size += 1 + ::google::protobuf::internal::WireFormatLite::Int64Size( this->expire()); } } GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = total_size; GOOGLE_SAFE_CONCURRENT_WRITES_END(); return total_size; }