return 0;
return solv_chksum_create_from_bin(type, buf);
}
+ %newobject from_bin;
+ static Chksum *from_bin(Id type, const unsigned char *str, size_t len) {
+ return len == solv_chksum_len(type) ? solv_chksum_create_from_bin(type, str) : 0;
+ }
+ %perlcode {
+ # make from_bin look like a constructor
+ undef *solv::Chksum::from_bin;
+ *solv::Chksum::from_bin = sub {
+ my $pkg = shift;
+ my $self = solvc::Chksum_from_bin(@_);
+ bless $self, $pkg if defined $self;
+ };
+ }
~Chksum() {
solv_chksum_free($self, 0);
}
%rename("==") __eq__;
#endif
bool __eq__(Chksum *chk) {
- int l;
- const unsigned char *b, *bo;
- if (!chk)
- return 0;
- if (solv_chksum_get_type($self) != solv_chksum_get_type(chk))
- return 0;
- b = solv_chksum_get($self, &l);
- bo = solv_chksum_get(chk, 0);
- return memcmp(b, bo, l) == 0;
+ return solv_chksum_cmp($self, chk);
}
#if defined(SWIGTCL)
%rename("!=") __ne__;
#endif
bool __ne__(Chksum *chk) {
- return !Chksum___eq__($self, chk);
+ return !solv_chksum_cmp($self, chk);
}
#if defined(SWIGRUBY)
%rename("to_s") __str__;
.RE
.\}
.sp
-Create an already finalized checksum object\&.
+Create an already finalized checksum object from a hex string\&.
+.sp
+.if n \{\
+.RS 4
+.\}
+.nf
+\fBChksum Chksum_from_bin(Id\fR \fItype\fR\fB, char *\fR\fIbin\fR\fB)\fR
+my \fI$chksum\fR \fB= solv::Chksum\->from_bin(\fR\fI$type\fR\fB,\fR \fI$bin\fR\fB)\fR;
+\fIchksum\fR \fB= solv\&.Chksum\&.from_bin(\fR\fItype\fR\fB,\fR \fIbin\fR\fB)\fR
+\fIchksum\fR \fB= Solv::Chksum\&.from_bin(\fR\fItype\fR\fB,\fR \fIbin\fR\fB)\fR
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+Create an already finalized checksum object from a binary checksum\&.
.SS "ATTRIBUTES"
.sp
.if n \{\
.RE
.\}
.sp
-Add a string to the checksum\&.
+Add a (binary) string to the checksum\&.
.sp
.if n \{\
.RS 4
chksum = solv.Chksum(type, hex)
chksum = Solv::Chksum.new(type, hex)
-Create an already finalized checksum object.
+Create an already finalized checksum object from a hex string.
+
+ Chksum Chksum_from_bin(Id type, char *bin)
+ my $chksum = solv::Chksum->from_bin($type, $bin);
+ chksum = solv.Chksum.from_bin(type, bin)
+ chksum = Solv::Chksum.from_bin(type, bin)
+
+Create an already finalized checksum object from a binary checksum.
=== ATTRIBUTES ===
chksum.add(str)
chksum.add(str)
-Add a string to the checksum.
+Add a (binary) string to the checksum.
void add_fp(FILE *fp)
$chksum->add_fp($file);